Hi,
I have a game object that has many child objects. I want to iterate through the child objects and store in an array of Gameobject.
Google for “unity child array.” First result.
Thanks Owen for the reply but I found the solution
This is what I do…
//obj is the game object that I have assigned through the inspector…it has many children //inside it
//YOu can simply copy and paste this function and use it…
//The gameobject whose children you want to traverse…
void replaceLightMap (GameObject obj)
{
for (int i = 0; i < obj.transform.childCount; i++) {
Transform tObjects = obj.transform.GetChild (i);
GameObject oObject = tObjects.gameObject;
print ("oObject is " + oObject);
}
}
This will print the name of all the child objects within the object obj.