让最底层的孩子

edw*_* au 1 unity-game-engine

我知道获得最高的父母是。transform.root如果我想获得最低的孩子并且在我不知道孩子名字的情况下该怎么办?

for (int i=0; i<theParent.childCount; i++) 
{
 int bottommost=theParent.childCount-1;
 Debug.Log(theParent.GetChild(bottommost).name);
}
Run Code Online (Sandbox Code Playgroud)

但是不是我期望的结果,我只是得到第一个孩子,但是我想要最底层的孩子。顺便说一句,我的意思是层次结构中最底层的孩子。

小智 6

lastChild = transform.GetChild(transform.childCount - 1);
Run Code Online (Sandbox Code Playgroud)