How to get children of a given an array of gameobjects?
Hi guys, the thing is that i need to get all children from each gameobject that is on one array, to track their position, and i'm having a headache with somehting that should be simple, hope some of you can see something i cant.
Here is what i got now: and what i see from inspector:! I just need the childs from that 3 (or maybe more) gameobjects
Answer by kbop2000 · May 05, 2020 at 04:01 AM
if you want first child, try this
void FillSpawnList()
{
List<GameObject> list = new List<GameObject>();
for (int i = 0; i < pathsList.Length; i++)
{
if (pathsList[i].transform.childCount == 0) continue;
Transform parent = pathsList[i].transform;
for (int j = 0; j < parent.childCount; ++j)
{
list.Add(parent.GetChild(j).gameObject);
}
}
spawnList = list.ToArray();
}
Thanks alot!!! just exactly what i was looking for!
Your answer
Follow this Question
Related Questions
How to change a game objects tag after it has been randomly selected? 0 Answers
changing the color of a random game object not working 0 Answers
Instantiated Child doesnt render if multiple objects share same name as parenting object? 1 Answer
Can i chose game objects as parts of an array in a script ? 1 Answer
How to find all GameObjects in Hierarchy by name and put them in an Array[] ? (C#) 1 Answer