Having a texture carry over multiple gameobjects

I’m working on a small test to learn how to code rendering and instantiating better. For some reason only the first of five gameobject get the current texture when the cycle reset.






public void Rendering()

Renderer rend=this.gameObject.transform.GetChild(0).GetChild(1).GetComponent();

sometimes when you try to address and change a material from an object in code, unity likes to make a new instance of the material instead of changing the original sometimes (seems to be a more common problem with clones for whatever reason). Anyways, if you want to be sure to change the material for everything using it, Instead of looking it up through the object, Make a drag and drop slot in the inspector for the material like this:

public Material somematerial;

and drag drop the actual material being used into the inspector!!!
then change the somematerial variable.

if you ever have the opposite problem and want to be sure your change is only effecting one object then you can force a new material instance like this:

         someobject.renderer.material = new Material(Shader.Find("Diffuse"));
         someobject.renderer.material.color = Color.blue;
         someobject.renderer.material.mainTexture = sometexture2D