- Home /
changing secondary texture dynamically?
I want to change the texture of a secondary material on my 3d model ( a smiley face, in this case).
When I use renderer.material.mainTexture, it changes the base texture of my model, and not the face texture Here is a screenshot of what my current texture/material set up is.
So, when I apply mainTexture = xyzTexture (example), the Texture of "body" gets changed whereas I want to change the texture of "happy" Anyone know any way to do this?
Do you really mean 2nd $$anonymous$$aterial?
Robertu explained how to change the 2nd texture on the first material (which is what you asked.) Like for the Detail Shader. But in your picture it looks like material Happy is on a sub$$anonymous$$esh. In that case, look at $$anonymous$$aterials[1]
(using just dot-material is a shortcut for $$anonymous$$aterials[0]
.
Answer by robertbu · Sep 25, 2013 at 02:02 PM
You use Material.SetTexture(). Note that the name to used is the one in the shader, which may be different from the one shown in the Inspector. You may have to open the shader to get the name.
$$anonymous$$aterial.SetTexture only has 3 parameters, though, according to the documentation, none of which are of my concern. Could you post an example, or possibly a direct way to do this for my script?
@Owen Reynolds is right. I did not read close enough. I think you want:
renderer.materials[1].mainTexture = xyzTexture;
Your answer
Follow this Question
Related Questions
Changing two different objects renderer colour 1 Answer
Renderer Removed When Scene Started 0 Answers
Why are my textures on planes flipped / reversed left-to-right? 1 Answer
Having a problem with the second material (on the same renderer) 0 Answers
Building under construction transitions from transparent glow to opaque texture 0 Answers