i have a game object , and i want a list off all the children for that model ?
In JS:
import System.Linq;
...
var allChildren = transform.Cast.<Transform>().Select(function(t) { return t.gameObject; }).ToArray();
In C#
using System.Linq;
...
var allChildren = transform.Cast<Transform>().Select(t=>t.gameObject).ToArray();
Did you want all of the descendants though?
Transform implements the IEnumerable interface therefore:
// if you want the transform component
Transform[] childsT = new Transform[transform.childCount];
// if you want the underlying GameObject
GameObject[] childsG = new GameObject[transform.childCount];
int i=0;
foreach(Transform child in transform)
{
childsT *= child;*
childsG = child.gameObject;
i++;
}
Note: this is the same as what Mike suggested but without the use of LINQ. I wonder which one is more efficient though. Internally both use the IEnumerable capabilities, but I think mine is better since is does not require a delegated method. Unless the compiler add the required code on the fly during execution (but this out of the scope of this question).
Transform transforms = gameObject.GetComponentsInChildren();
foreach(Transform trans in transforms)
{
Debug.Log(tra.name);
}
This will print all the children of this perticular game object.