- Home /
How to change a specific material when the mesh has more than one material?
Hi,
I'm using the WWW class to change the mesh material texture. My problem is that my mesh contains more than one material (elements 0 and 1) and when I'm applying a "renderer.material.mainTexture", it only changes the "element 0" material texture. But I want it to change the "element 1" material. Can anyone help on how to go about doing this?
***Here is the script I'm using:
// Get the latest webcam shot from outside "Friday's" in Times Square var url = "http://images.earthcam.com/ec_metros/ourcams/fridays.jpg"; function Start () { // Start a download of the given URL var www : WWW = new WWW (url);
// Wait for download to complete yield www;
// assign texture
renderer.material.mainTexture = www.texture; }
Answer by Eric5h5 · Mar 24, 2010 at 06:06 PM
You have to change renderer.materials, rather than renderer.material.
var mats = renderer.materials;
mats[1].mainTexture = www.texture;
renderer.materials = mats;
Answer by L34D3R · May 08, 2015 at 05:13 AM
If you want to change all material elements of object's children than here is the answer: http://answers.unity3d.com/questions/653171/how-to-change-materials-for-all-material-elements.html
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
How to change the color of all objects that use the same material? 0 Answers
Can I access the Material of an animated object via code? 1 Answer
Issue with Mesh Renderer and Skinned Mesh Renderer 0 Answers
Changing material of objects by the tag in different scenes 0 Answers