- Home /
Question by
$$anonymous$$ · Aug 15, 2014 at 03:52 PM ·
texturematerial
change texture of specific material in object that contains 2 materials?
I have one object with two materials. i want to change the texture of one of the specific materials programatically. Can i do this and if so how?
Comment
Best Answer
Answer by zee_ola05 · Aug 15, 2014 at 05:57 PM
This is one way to do it, you will have to know the name of the material and name of the texture property.
Material foundMaterial = null;
foreach(Material mat in renderer.materials)
{
if(mat.name == "my-material")
{
foundMaterial = mat;
}
}
if(foundMaterial)
{
foundMaterial.SetTexture("propertyName", myTexture);
}
To find the property name of your texture, look at your shader script. Check highlighted.