Version: 2023.1

GameObject

class in UnityEngine

/

继承自:Object

切换到手册

描述

Unity 场景中所有实体的基类。

Note: Many variables in the GameObject class have been removed. To access GameObject.renderer in csharp, for example, use GetComponent<Renderer>() instead.

See Also: Component.

变量

activeInHierarchy定义 GameObject 在 Scene 中是否处于活动状态。
activeSelf此 GameObject 的本地活动状态。(只读)
isStatic获取并设置 GameObject 的 StaticEditorFlags。
layerThe layer the GameObject is in.
scene该 GameObject 所属的场景。
sceneCullingMaskUnity 用于确定在哪个场景中渲染该 GameObject 的场景剔除遮罩。
tagThe tag of this GameObject.
transform附加到此 GameObject 的 Transform。

构造函数

GameObjectCreates a new GameObject, named name.

公共函数

AddComponentAdds a component class of type componentType to the GameObject. C# Users can use a generic version.
BroadcastMessageCalls the method named methodName on every MonoBehaviour in this GameObject or any of its children.
CompareTagIs this GameObject tagged with tag ?
GetComponentGets a reference to a component of type T on the specified GameObject.
GetComponentInChildrenGets a reference to a component of type T on the specified GameObject, or any child of the GameObject.
GetComponentInParentGets a reference to a component of type T on the specified GameObject, or any parent of the GameObject.
GetComponentsGets references to all components of type T on the specified GameObject.
GetComponentsInChildrenGets references to all components of type T on the specified GameObject, and any child of the GameObject.
GetComponentsInParentGets references to all components of type T on the specified GameObject, and any parent of the GameObject.
SendMessageCalls the method named methodName on every MonoBehaviour in this GameObject.
SendMessageUpwardsCalls the method named methodName on every MonoBehaviour in this GameObject and on every ancestor of the behaviour.
SetActive根据给定的值 true 或 /false/,激活/停用 GameObject。
TryGetComponent获取指定类型的组件(如果存在)。

静态函数

CreatePrimitiveCreates a GameObject with a primitive mesh renderer and appropriate collider.
Find按 name 查找 GameObject,然后返回它。
FindGameObjectsWithTag返回标签为 tag 的活动 GameObjects 的数组。如果未找到任何 GameObject,则返回空数组。
FindWithTag返回一个标记为 tag 的活动 GameObject。如果未找到 GameObject,则返回 null。

继承的成员

变量

hideFlags该对象应该隐藏、随场景一起保存还是由用户修改?
name对象的名称。

公共函数

GetInstanceIDGets the instance ID of the object.
ToString返回对象的名称。

静态函数

Destroy移除 GameObject、组件或资源。
DestroyImmediate立即销毁对象 /obj/。强烈建议您改用 Destroy。
DontDestroyOnLoad在加载新的 Scene 时,请勿销毁 Object。
FindAnyObjectByTypeRetrieves any active loaded object of Type type.
FindFirstObjectByTypeRetrieves the first active loaded object of Type type.
FindObjectsByTypeRetrieves a list of all loaded objects of Type type.
Instantiate克隆 original 对象并返回克隆对象。

运算符

bool该对象是否存在?
operator !=比较两个对象是否引用不同的对象。
operator ==比较两个对象引用,判断它们是否引用同一个对象。