Sooo, I have an object with two materials on it. I create and store a reference to a new material, and can set the one color just fine by doing this pseudocode:
material1Copy = new Material(GetComponent<Renderer>().sharedMaterial)
material1Copy.color = whatever
GetComponent<Renderer>().material = material1Copy;
However, when trying to change material 1 AND 2 like
material1Copy = new Material(GetComponent<Renderer>().sharedMaterials[0]);
material2Copy = new Material(GetComponent<Renderer>().sharedMaterials[1]);
material1Copy.color = whateverColor1
material2Copy.color = whateverColor2
Material[] myMaterials = new Material[] { material1Copy, material2Copy };
GetComponent<Renderer>().sharedMaterials = myMaterials;
It doesnāt appear to work in the game view⦠but if I click on the object in the inspector while the game is playing, and click on the circles next to the materials, they update and magically display the right colors.
What am I missing?
This is in 5.1.1 using the standard shader.