Why when coloring in script some objects it's coloring all the objects ?

for (int i = 0; i <  listfoundobj.Count; i++)
        {
            listfoundobj[i].GetComponent<Renderer>().sharedMaterial.color = Color.green;
        }

listfoundobj contain 4 items.

And i have a grid of objects size 10x10 and it keep coloring the whole grid the whole 100 objects but i want it to color only this 4 objects.

you are using sharedmaterial

1 Like

Now it’s coloring them using only material. But also give me exception:

listfoundobj[i].GetComponent<Renderer>().material.color = Color.green;

Instantiating material due to calling renderer.material during edit mode. This will leak materials into the scene. You most likely want to use renderer.sharedMaterial instead.