I have a mesh with two materials. I want to use the “renderer.material.color = Color.white;” command on the second one. How do I do that?
Have a look at the renderer.materials array. You should end up with some code like:
renderer.materials[1].color = Color.white;
Thanks for that. Now I have another problem: how do I change the material all together? (I have a texture with some shaders attached that I want to use.)
If you want to change the entire material, you can simply assign a new one in its place:
renderer.materials[1] = otherMaterial;
Alternatively, have a look at the properties for a Material and you can access them and reassign their values just like you did with the color. For a texture, it might be:
renderer.materials[1].mainTexture = newTexture;
Still having some problems. Here is a sample of my code:
function torsoDesign (idx) {
renderer.materials[1].mainTexture = torsoDesignArray[idx];
}
function changeCharacter () {
print ("Changing...");
SendMessage("torsoDesign", 1);
renderer.materials[0].color = Color.red;
}
I call “changeCharacter” from another script. The color of the first material changes, but the texture does not.
EDIT: It works now! Forgot to assign a variable. Thanks a bundle for your help!