新建若干个cube其父子关系如下:
public class FindChild : MonoBehaviour
{
Transform FindChildCube(string childName,Transform parent)
{
if(childName==parent.name)return parent;
if(parent.childCount<1)return null;
Transform obj=null;
for(int i=0;i<parent.childCount;i++)
{
var t=parent.GetChild(i);
obj=FindChildCube(childName,t);
if(obj!=null)break;
}
return obj;
}
private void Start() {
var t=FindChildCube("Cube (6)",transform);
if(t)Debug.Log(t.name);
}
}