获取到GameObject–>拿到成员transform–>利用Transform中的方法查找组件 ②Component: a).GetComponent() b).GetComponentInChildren c).GetComponentInParent d).GetCompontents e).GetComponentsInChildren f).GetComponentsInParent g).FindObjectOfType<>()依据组件类型 h).FindObjectsOfType<>() ③Transform: 已知...
3.Component - T GetComponentInChildren<T>(bool includeInactive) 支持子节点,孙节点的搜索。 如果自身存在这个组件,可返回自身 如果是非激活的对象,第二个参数includeInactive设为true即可搜索到 但缺点是只能搜索组件,不能按照名称搜索 用GetComponentsInChildren可以搜索多个,返回数组 GetComponentInParent规则同此条...
GameObject.FindWithTag GameObject.FindGameObjectWithTag GameObject.FindGameObjectsWithTag 通过层级关系获取对象 Transform.GetChild Transform.parent Transform.root 获取组件 GameObject.GetComponent\<T\>() GameObject.GetComponents\<T\>() GameObject.GetComponentInParent\<T\>() GameObject.GetComponentsInParent\<T...
public Component GetComponentInParent (Type t); 参数 t 要检索的组件的类型。 返回 Component 匹配类型的组件(如果找到)。 描述 返回GameObject 或其任何父项中类型为 type 的组件。 向上递归,直到其找到有效组件为止。如果未找到组件,则返回 null。仅返回活动 GameObject 上的组件。public T GetComponentIn...
GetComponent 获取游戏对象的组件,脚本 GetComponentInChildren 返回此游戏对象或者它的所有子对象上(深度优先)的类型为type的组件。 GetComponentInParent 从父对象查找组件。 GetComponents 返回该游戏对象所有type类型的组件列表。 GetComponentsInChildren *返回此游戏对象与其子对象所有type类型的组件。* GetComponentsIn...
// Hand must not have a parent in the Hierarchy view. hand = GameObject.Find("/Hand"); 1. 2. 3. 4. 5. 6. 3)通过名字或标签 GameObject.Find() 和 GameObject.FindWithTag(); 两个函数都是返回游戏对象 //GameObject.Find是遍历整个当前场景,挨个查找,效率偏低,非特殊情况一般不要使用 ...
parent:返回物体变换的父级 root:返回最高层次的游戏物体的变换 七、Transform类中的常用函数 Translate:按指定的方向和距离平移 Rotate:按指定的欧拉角旋转 RotateAround:按给定旋转轴和旋转角度旋转 LookAt:旋转使得自身的前方向指向目标的位置 Find:通过名字查找子物体并返回,返回值类型为transform ...
重新编辑GetGOandComponent脚本如下 输出结果 Transform.Find需要的字符串参数不是物体名称,而是要获取的物体相对脚本所在物体的路径 “”可以用来指代挂载脚本的物体本身,“..”可以用来指代挂载脚本的物体的父物体,“../..”则是父物体的父物体 也可以通过Transform.parent获取父物体,通过Transform.root获取最上一级的...
public Component GetComponent(Type type); public Component GetComponentInChildren(Type t, bool includeInactive); public Component GetComponentInParent(Type t, bool includeInactive); 当然,这些接口也有其他的变体,这里只关注这三个常用的接口,因为查找行为和GameObject.Find有些类似,这里就一并总结了。 GetCompon...
②得到Component的方式 1)找到一个符合条件的之后就返回找到的这个并且不再寻找 GetComponent// gameObject.GetComponent<RotateSelf>() GetComponentInChildren GetComponentInParent 2)会找出所有的符合条件的,并做成一个数组返回 GetComponents GetComponentsInChildren ...