UnityAPI手册-2019.4官网版
文集大纲加载中……
本文档使用 MrDoc 发布
-
+
首页
GameObject
# GameObject class in UnityEngine / 继承自:[Object](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.html) ## 描述 Unity 场景中所有实体的基类。 **注意:** [GameObject](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.html) 类中的很多变量已被删除。例如, 要访问 csharp 中的 GameObject.renderer,请改用 GetComponent<Renderer>()。 另请参阅:Component。 ## 变量 | [activeInHierarchy](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-activeInHierarchy.html) | 定义 GameObject 在 Scene 中是否处于活动状态。 | | -------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------- | | [activeSelf](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-activeSelf.html) | 此 GameObject 的本地活动状态。(只读) | | [isStatic](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-isStatic.html) | 获取并设置 GameObject 的 StaticEditorFlags。 | | [layer](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-layer.html) | 该游戏对象所在的层。 | | [scene](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-scene.html) | 该 GameObject 所属的场景。 | | [sceneCullingMask](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-sceneCullingMask.html) | Unity 用于确定在哪个场景中渲染该 GameObject 的场景剔除遮罩。 | | [tag](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-tag.html) | 此游戏对象的标签。 | | [transform](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-transform.html) | 附加到此 GameObject 的 Transform。 | ## 构造函数 | [GameObject](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject-ctor.html) | 创建一个名为 name 的新游戏对象。 | | ------------------------------------------------------------------------------------ | ---------------------------------- | ## 公共函数 | [AddComponent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.AddComponent.html) | 将名为 className 的组件类添加到该游戏对象。 | | -------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------- | | [BroadcastMessage](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.BroadcastMessage.html) | 调用此游戏对象或其任何子项中的每个 MonoBehaviour 上名为 methodName 的方法。 | | [CompareTag](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.CompareTag.html) | 此游戏对象是否使用 tag 进行了标记? | | [GetComponent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponent.html) | 如果游戏对象附加了类型为 type 的组件,则将其返回,否则返回 null。 | | [GetComponentInChildren](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponentInChildren.html) | 使用深度首次搜索返回 GameObject 或其任何子项中类型为 type 的组件。 | | [GetComponentInParent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponentInParent.html) | 获取 GameObject 或其任何父项中 Type type 的组件。 | | [GetComponents](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponents.html) | 返回 GameObject 中类型为 type 的所有组件。 | | [GetComponentsInChildren](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponentsInChildren.html) | 返回 GameObject 或其任何子项中类型为 type 的所有组件。 | | [GetComponentsInParent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.GetComponentsInParent.html) | 返回 GameObject 或其任何父项中类型为 type 的所有组件。 | | [SendMessage](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.SendMessage.html) | 调用此游戏对象中的每个 MonoBehaviour 上名为 methodName 的方法。 | | [SendMessageUpwards](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.SendMessageUpwards.html) | 调用此游戏对象中的每个 MonoBehaviour 上或此行为的每个父级上名为 methodName 的方法。 | | [SetActive](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.SetActive.html) | 根据给定的值 true 或 /false/,激活/停用 GameObject。 | | [TryGetComponent](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.TryGetComponent.html) | 获取指定类型的组件(如果存在)。 | ## 静态函数 | [CreatePrimitive](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.CreatePrimitive.html) | 创建一个具有原始网格渲染器和相应碰撞体的游戏对象。 | | ------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------- | | [Find](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.Find.html) | 按 name 查找 GameObject,然后返回它。 | | [FindGameObjectsWithTag](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.FindGameObjectsWithTag.html) | 返回标签为 tag 的活动 GameObjects 的数组。如果未找到任何 GameObject,则返回空数组。 | | [FindWithTag](https://docs.unity3d.com/cn/2019.4/ScriptReference/GameObject.FindWithTag.html) | 返回一个标记为 tag 的活动 GameObject。如果未找到 GameObject,则返回 null。 | ## 继承的成员 ## 变量 | [hideFlags](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object-hideFlags.html) | 该对象应该隐藏、随场景一起保存还是由用户修改? | | ------------------------------------------------------------------------------------ | ------------------------------------------------ | | [name](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object-name.html) | 对象的名称。 | ## 公共函数 | [GetInstanceID](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.GetInstanceID.html) | 返回对象的实例 ID。 | | -------------------------------------------------------------------------------------------- | --------------------- | | [ToString](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.ToString.html) | 返回对象的名称。 | ## 静态函数 | [Destroy](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.Destroy.html) | 移除 GameObject、组件或资源。 | | ---------------------------------------------------------------------------------------------------- | ------------------------------------------------ | | [DestroyImmediate](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.DestroyImmediate.html) | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 | | [DontDestroyOnLoad](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.DontDestroyOnLoad.html) | 在加载新的 Scene 时,请勿销毁 Object。 | | [FindObjectOfType](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.FindObjectOfType.html) | 返回第一个类型为 type 的已加载的激活对象。 | | [FindObjectsOfType](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.FindObjectsOfType.html) | 返回所有类型为 type 的已加载的激活对象的列表。 | | [Instantiate](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object.Instantiate.html) | 克隆 original 对象并返回克隆对象。 | ## 运算符 | [bool](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object-operator_Object.html) | 该对象是否存在? | | ---------------------------------------------------------------------------------------- | ------------------------------------------------ | | [operator !=](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object-operator_ne.html) | 比较两个对象是否引用不同的对象。 | | [operator ==](https://docs.unity3d.com/cn/2019.4/ScriptReference/Object-operator_eq.html) | 比较两个对象引用,判断它们是否引用同一个对象。 |
da
2022年5月26日 17:59
转发文档
收藏文档
上一篇
下一篇
手机扫码
复制链接
手机扫一扫转发分享
复制链接
关于 MrDoc
觅思文档MrDoc
是
州的先生
开发并开源的在线文档系统,其适合作为个人和小型团队的云笔记、文档和知识库管理工具。
如果觅思文档给你或你的团队带来了帮助,欢迎对作者进行一些打赏捐助,这将有力支持作者持续投入精力更新和维护觅思文档,感谢你的捐助!
>>>捐助鸣谢列表
微信
支付宝
QQ
PayPal
Markdown文件
分享
链接
类型
密码
更新密码