- Home /
changing both texture images on a material
i have an object which has a diffuse detail material attached. i want to be able to change both the main texture and the detail texture at different times. how would i refer to each element to do so? (the scenario is a car which changes colour on the main texture, but also gets dirtier on the detail texture
doorMaterial.mainTexture = doorColour[doorTexture];
this is the code i am using to change the car colour on the main texture
thanks
Answer by luizgpa · Jan 03, 2012 at 04:10 PM
Use Material.SetTexture(). To know the name of a texture you will need to look at shader code used by the material. For builtin shaders take a look here.
The code for a material using Diffuse Detail would be:
doorMaterial.SetTexture("_Detail", detailTexture);
thankyou for that. I've used the _detail and an array to change them. do you know how i could fade between 2 details?
I can think of 2 ways:
1 - create a texture dynamically that mix 2 detail textures you want to fade.
2 - write a shader, based on the built-in, that takes 2 textures ins$$anonymous$$d of 1 and interpolate between them.
I don't know how are you planning to use it, but I think the 2nd approach would be better in most of the cases. It requires some shader program$$anonymous$$g skills though.
I have gone with option 2, thank you. the shader has a main texture with 3 overlaying details. I'm just working out now how to apply alpha channels to the details to fade each one in