public static GameObject CreateGameObject (string name, params Type[] types);

Parameters

name游戏对象的名称。
types创建时要添加到游戏对象的可选类型。
sceneScene where the GameObject should be created.
hideFlagsHideFlags to assign to the GameObject.

Returns

GameObject Returns the GameObject that was created.

Description

创建一个新的游戏对象。

using UnityEngine;
using UnityEditor;

public class CreateComponentExample { [MenuItem("ObjectFactoryExample/Create Camera GameObject")] public void CreateCameraEditor() { Selection.activeGameObject = ObjectFactory.CreateGameObject("Camera", typeof(Camera)); } }