I want to get the number of the Childs Children. The Script is attached to this GameObject. The Counts of the gradchild is changing.
I wrote:
for (int s = 0; s < 10; s++)
{
GameObject way = this.transform.GetChild(0).GetChild(s).gameObject;
}
But actually I dont want to write 10, i want to write something like: grandChild.count or grandChild.length
thank you a lot!
for( int childIndex = 0 ; childIndex < transform.childCount ; ++childCount )
{
Transform child = transform.GetChild( childIndex ) ;
for( int grandChildIndex = 0 ; grandChildIndex < child.childCount ; ++grandChildIndex )
{
GameObject way = child.GetChild(grandChildIndex).gameObject;
}
}
If you want to only do something with the grandchildren of the first child
Transform child = transform.GetChild( 0 ) ;
for( int grandChildIndex = 0 ; grandChildIndex < child.childCount ; ++grandChildIndex )
{
GameObject way = child.GetChild(grandChildIndex).gameObject;
}