Changing texture of childrens

Hey,

I have the following setup: I have an empty game object, which has many childs. I would like to create a script, which I can attach to the empty game object, and do the following:

It loops trought the childs, and it changes it’s main textures. If the object name is “roadEdge”, than it skip the object, otherwise, it changes the main texture.

I have tried to do it, but I cant get it working.

Can anyone help me?

2 Answers

2

This might be a more concise way (in C#):

Renderer[] renderers = transform.GetComponentsInChildren<Renderer>();
foreach (Renderer r in renderers)
{
    r.material.mainTexture = myTexture;
}

foreach(Transform childs in transform)
{
for(int cnt = 0; cnt < childs.Lenght; childs++)
{
if(childs[cnt].name != roadEdge)
{
childs[cnt].renderer.material.mainTexture = myTexture;
}
}

}

I have copied it to the script, but I have received 10 errors, starting in this line: foreach(Transform[] childs in transform) I am using javascript.