how to find all clones of a gameobject?

in my platform game there is a original platform called “platform1”. this platform will be destroyed after short time. the following four platforms are clones with the name “platform1(Clone)”. They are taged with the tag “Ground”.

i want to change the textures of every of this four clone platforms.

for this i use:

var tex3 : Texture2D = Resources.Load("platform1_tex2");
platforms.renderer.material.mainTexture = tex3;

when i use this it changes just the texture of one of this four platforms:

var platforms : GameObject;
platforms = GameObject.Find("platform1(Clone)");

when i use this i got this error: The object of type ‘GameObject’ has been destroyed but you are still trying to access it.

var platforms : GameObject;
platforms = GameObject.FindWithTag("Ground");

This is not a good way to go about this. If you are changing every one of the platforms’ textures, colors, or whatever then the platforms should all use one material and then you can change that shared material. If you’ve already committed to using that material on many things, then you will have to find each of the objects using a FindGameObjectsWithTag or another Find type command which returns multiple objects, then iterate through the returned array and update each one of the objects materials (which will copy the material and each will have their own unique copy).

thank you for your reply.

the original platform1 and every clone uses the same material. and nothing else use this material.

now i use this:

var platforms = GameObject.FindGameObjectsWithTag("Ground");

and

var tex3 : Texture2D = Resources.Load("platform1_tex2");
platforms.renderer.material.mainTexture = tex3;

and i got following error: ‘renderer’ is not a member of ‘UnityEngine.GameObject[ ]’.

Or course it isn’t, because renderer is part of a gameObject, not part of a gameObject[ ] (an array of gameObjects). You’ll have to modify each one by iterating through that array.

ok. i have never done this before. can you please tell me how i can do this?

Just go read how to iterate through an array. It’s pretty common, you’ll find yourself doing it a lot in Unity.

ok. i have read about it in the manual. but i check it not really.

now i use:

var platforms : GameObject[];
platforms = GameObject.FindGameObjectsWithTag("Ground");

and

for(GameObject in platforms ){
var tex3 : Texture2D = Resources.Load("platform1_tex2");
renderer.material.mainTexture = tex3;}

same error: ‘renderer’ is not a member of ‘UnityEngine.GameObject[ ]’.

i am going crazy! can you please tell me what i do false?

You are almost there. You just need to assign each texture to the items in the slots of the array. Something like this:

for(var x: int = 0; x < platforms.length; x++ ){
var tex3 : Texture2D = Resources.Load("platform1_tex2");
platforms[x].renderer.material.mainTexture = tex3;
}

Mind you, this isn’t tested, but you should get the idea of how to deal with the individual data in the array.

You should not use GameObject as a variable. try:

for(var go : GameObject in platforms ){}

thank you. i am an idiot. i forgot to delete one line and now i use this and it works:

var platforms : GameObject[];
platforms = GameObject.FindGameObjectsWithTag("Ground");
for(var everyplatform : GameObject in platforms ){
var tex3 : Texture2D = Resources.Load("platform1_tex2");
everyplatform.renderer.material.mainTexture = tex3;
}

thank you all!

See? You learned something, you learn more when people point you in the right direction than when they just type up things for you.