语言英语
  • C#

ObjectFactory.CreateGameObject

声明

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

声明

public static GameObject CreateGameObject(SceneManagement.Scene scene, HideFlags hideFlags, string name, params Type[] types);

参数

名称 GameObject 的名称。
类型 创建时要添加到 GameObject 的可选类型。
场景 应该在其中创建 GameObject 的场景。
HideFlags 要分配给 GameObject 的 HideFlags。

返回值

GameObject 返回创建的 GameObject。

描述

创建一个新的 GameObject。

using UnityEngine;
using UnityEditor;

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

Did you find this page useful? Please give it a rating: