GetComponent()详解

                MyComponment myCom=gameObject.GetComponent();

		MyComponment childCom=gameObject.GetComponentInChildren();

		MyComponment[] comS=gameObject.GetComponents();

		MyComponment[] comS1=gameObject.GetComponentsInChildren();

		MyComponment[] comSTrue=gameObject.GetComponentsInChildren(true);

		MyComponment[] comSFalse=gameObject.GetComponentsInChildren(false);

这几句话的区别

1GetCompoment ()从当前游戏对象获取组件T,只在当前游戏对象中获取,没得到的就返回null,不会去子物体中去寻找。

2GetCompomentInChildren()先从本对象中找,有就返回,没就子物体中找,知道找完为止。

3GetComponents()获取本游戏对象的所有T组件,不会去子物体中找。

4GetComponentsInChildren()=GetComponentsInChildren(true)取本游戏对象及子物体的所有组件

5GetComponentsInChildren(false)取本游戏对象及子物体的所有组件 除开非活跃的游戏对象,不是该组件是否活跃。


你可能感兴趣的:(Unity)