- Home /
Change between 2 textures based on a variable
Hi, I'm just starting to try to figure out shaders. This is for a game I am making as a class project. I saw how to set a color variable in a shader from another script: renderer.material.SetColor(); but what I really need is a way to switch between two textures, with blended versions in between. In the game the player is supposed to change to a different texture to indicate that they are closer to the time limit. (The player is infected and turning into a mutant creature over time unless they stop it) There are items that can give them more time. I have a variable that tracks the percent of the time bar remaining. I sort of saw a few ways to blend two textures but I played around for a while and could not figure out how to have a larger percent of one texture or another, never mind a way to externally set the percent of each being used. I hope my situation is clear and I'd be glad to clarify. Could you please help my out. Thank you a bunch!
Unless some guru on this 'site knows of a command I really don't think it is possible. The best you could do is have 2 textures, one placed just infront of the other, and modify the alpha of the front texture. If you are not using planes/flat surfaces, there could be a problem with z-sorting if you dont get the distance between the 2 textures set right.
Answer by Maulik2208 · Dec 10, 2012 at 10:31 AM
For changing texture use Gameobject.material.maintexture = Texturename; for more info on scripting have a look on this link link text
Hope this will work for you.....Enjoy and don't forget to Accept as a correct answer if works fine for you.....
I'm sorry but that's not what I wanted. I wanted a way to shift between two textures mixing them at different percents in between. So I wanted to go from fully one texture to fully another (with the percent of each based on a variale). So what I really want to know is how to combine two textures such that thereis more of one than another and how to set the weight of each. Thanks.
Your answer
![](https://koobas.hobune.stream/wayback/20220613085225im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How can I combine a color texture with a b&w texture and get color? 2 Answers
Combine Shaders 0 Answers
wood embers shader/texture 0 Answers
How do I build A texture from decals? 0 Answers
Cutout Material is not showing texture transparency? 0 Answers