I have this prefab which contains a Plane mesh, which uses the Transparent/Diffuse shader. The texture is a gray PNG with alpha, and I want to use the shader’s MainColor to colorize that PNG.
In Editor, this is all well and good.
I have several instances of this prefab, and I need to change the colors of the various instances dynamically. So I get the prefab instances by name and set the color
p = gameObject.Find("Plane");
if (!p)
Debug.LogError("spot plane not found");
p.renderer.material.SetColor ("_Color", scolor);
The odd thing is, it sets ONE of the instances, not all of them, and it’s not always the same instance. I can replace ‘scolor’ with, say, Color.red, and then one of the instance will colorize. All others stay at the default color.
I would have thought that if it was altering the shader at a ‘material’ level, then all instances would have the new color.
What’s the trick to this?