| Parameter | Description |
|---|---|
| name | The name of the new GameObject. |
| types | The types of the components to add to the new GameObject. |
GameObject The GameObject that the method created.
Creates a new GameObject with the specified name and components.
The method adds the components while the GameObject is inactive, then activates it and gives it the default parent for new objects. To create the GameObject in a specific scene, use the overload that takes a Scene.
using UnityEngine; using UnityEditor;
public class CreateComponentExample { [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); } }
| Parameter | Description |
|---|---|
| scene | The scene to create the GameObject in. |
| hideFlags | The hide flags to assign to the GameObject. |
| name | The name of the new GameObject. |
| types | The types of the components to add to the new GameObject. |
GameObject The GameObject that the method created.
Creates a new GameObject with the specified name and components, in a specific scene and with hide flags.
The method throws an exception if scene isn't valid.