- Home /
Material.SetColor and Material.color are not working properly
Hi Everybody! i am actually new to shader world so there is something i can't understand about it.
I am trying to clone(duplicate) a material in either Editor or Runtime that is pre-created and saved to Resources folder by using the following script (Please note that i am using the Standard Shader):-
Material mainMat = Resources.Load(matPath) as Material;
Material clonedMat = new Material(mainMat);
then i would like to change this cloned material color using any of the following scripts but something goes wrong with the shader
Color color = new Color(191f, 0f , 0f , 255f);
clonedMat.SetColor("_Color", color);
or
Color color = new Color(191f, 0f , 0f , 255f);
clonedMat.color = color;
I have read about Accessing and Modifying Material parameters via script in this link but i can't really figure out the point i miss.
Do i really miss something to update or access the shader before changing a material's color? Please could anyone provide a sample about the material.EnableKeyword(string Keyword) function as i can't get to the way it works.