- Home /
Question by
pickle chips · Jul 08, 2013 at 10:30 PM ·
materialcolour
Change the colour of a specififc material?
I've read endless amounts of answers already pertaining to this topic, but none of them seemed to work correctly.
Basically, what I want to do is change the colour of two out of three materials on an object (But to different colours) and I can't seem to get it to work properly. This is what I've tried:
foreach (Material matt in helmet.renderer.materials) {
if (matt.name == "Helmet") {
matt.color = Color.red;
matt.SetFloat("_Shininess", 0.2f);
}
else if (matt.name == "HelmetTop")
matt.color = new Color (pc.EquippedHelmet.BrushColour.R, pc.EquippedHelmet.BrushColour.G, pc.EquippedHelmet.BrushColour.B);
}
}
When I play the game and look in the inspector, I can see it created a new instance of each material than I can change through the inspector, which works, but I want the code to change the colour of the two materials...
Thanks
Comment
Best Answer
Answer by supercouge · Jul 08, 2013 at 11:12 PM
You should try:
..
if (matt.name == "Helmet (Instance)")
..
..
else if (matt.name == "HelmetTop (Instance)")
..
..
You sir, are a genius. Thank you so much! That was exactly my problem!
Your answer
![](https://koobas.hobune.stream/wayback/20220613105724im_/https://answers.unity.com/themes/thub/images/avi.jpg)