public void Start(){
Transform item = FindChild (transform, "d");
print (item.name);
}
public static Transform FindChild(Transform parent,string name){
Transform item = null;
//寻找自身一级目录下的子物体有没有该名字的物体
item=parent.Find(name);
//如果有返回他
if(item!=null) return item;
Transform go = null;
//如果没有,就把该父物体所有一级子物体下所有的二级子物体找一遍(以次类推);
for (int i = 0; i < parent.childCount; i++) {
go = FindChild (parent.GetChild (i), name);
if (go != null) {
return go;
}
}
return null;
}
网友评论