getcomponent等等

1.脚本挂到GameObject上,gameobject变量可以获得该脚本依附的对象,同理transform等信息也可以获得

 

2.在脚本中使用gameObject.transform.parent,可以获得你所依附的对象的父对象,如果再想往上一级获取,可以gameObject.transform.parent.parent

 

3.GetComponent<T>():获取对象中指定类型的控件(脚本)

   GetComponentInChildren<T>():获取对象的子对象中指定类型的控件,注意的是假如父对象拥有该控件,首先获取的是父对象的控件(它寻找的对象也包括父对象的)

   GetComponents<T>()、GetComponentsInChildren<T>()也是一样的,只不过是获取数组而已,也是要注意GetComponentsInChildren,寻找的对象也包括父对象的

 

4.GetComponentsInChildren获取的是脚本所依附的对象的所有子对象,包括子对象的子对象(GetComponentInChildren同理)

posted on 2015-09-23 18:35  public_void_digua  阅读(318)  评论(0)    收藏  举报

导航