- Home /
change a material from multiple materials
Hello everyone, I've got a problem with changing a material on an object which has multiple materials (2)
renderer.material = Off; (WORKS it changes the first material)
renderer.materials[0] = Off; (Doesn't change any material)
<= this is what I'm looking for , choosing what material in the list I want to change , but it doesn't work ! How can I do ? Thanks for reading
Answer by Bluestrike · Feb 23, 2012 at 07:40 PM
http://answers.unity3d.com/questions/13751/how-to-change-a-specific-material-when-the-mesh-ha.html has an awnser.
var materials : Material[] = mesh.renderer.materials;
materials[0] = crateMat1snow;
mesh.renderer.materials = materials;
That works but generates a unity error:
UnityEngine.Renderer:get_materials() in unity 3.5Instantiating 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.
Your answer
![](https://koobas.hobune.stream/wayback/20220613005301im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help Changing Materials On Button Click 0 Answers
change skybox via script help ? 1 Answer
Change material per element 1 Answer
How can I add another "layer" to my shader? 1 Answer
How can I overlay an image across multiple game objects? 1 Answer