文档

Unity Engine

Unity Engine

CreateGameObject

Creates a new GameObject.
阅读时间1 分钟最后更新于 1 个月前

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor.CoreModule

CreateGameObject(Scene, HideFlags, string, Type[])

Creates a new GameObject.
public static GameObject CreateGameObject(Scene scene, HideFlags hideFlags, string name, params Type[] types)

Parameters

scene

Scene where the GameObject should be created.

hideFlags

HideFlags to assign to the GameObject.

name

Name of the GameObject.

types

The optional types to add to the GameObject when created.

Returns

Type

Description

GameObjectReturns the GameObject that was created.

Examples

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

CreateGameObject(string, Type[])

Creates a new GameObject.
public static GameObject CreateGameObject(string name, params Type[] types)

Parameters

name

Name of the GameObject.

types

The optional types to add to the GameObject when created.

Returns

Type

Description

GameObjectReturns the GameObject that was created.

Examples

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