Fill Array with Children

Greetings,

How would I go about filling an array with children of the parent that the script is attached to? I’ve tried this.GetComponentsInParent(GameObject), is that even remotely right?

Thanks!

Hello,
Basen!

You can use this phrase:

List<GameObject> children = new List<GameObject>();
foreach (Transform child in this.gameObject.transform) 
{
  children.Add(child.gameObject);
}

So, as you can see, every gameObject’s transform contains info about its children.

See Unity - Scripting API: Transform