So far i have tried this to get all children of the object but it is only brings two child object. Not all child of the child. how do i get all and loop through to get specific name object
Transform[] objChild = gameObject.transform.GetComponentsInChildren<Transform>();
for (var i = 0; i < objChild.Length; i++)
{
objWheel.Add(objChild[i].gameObject.transform.GetChild(i).gameObject);
objWheelAnimation.Add(objChild[i].gameObject.transform.GetChild(i).GetComponent<Animation>());
if (objChild[i].gameObject.name.Contains("Wheel Rotation"))
{
}
}
If you want to get each and every child of a parent GameObject then, Here is the smallest and simple code snippet. Attach this to the parent GameObject.
foreach (Transform g in transform.GetComponentsInChildren<Transform>())
{
Debug.Log(g.name);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With