How to access children transforms from parent GO script?

Hi!

I have a gameObject with some structure inside like this:
Soldier/Armor
Soldier/Head
Soldier/Arms

How I can access to renderer.material.mainTexture or renderer.material.color of children transforms only (ie Armor.transform) from csharp script on parent object (Soldier)?

Thanks!

1 Answer

1

You can use Transform.Find() to find the transforms by name. Then you can use the renderer in the transform.

Transform trans = transform.find("Head");
trans.renderer.material.color = Color.red;

If you have a hierarchy of transforms, you can also walk the hierarchy:

Transform trans = transform.find("Body/Leg/toes");