- Home /
Fade mesh material color to texture
Hey all,
I want to have an enemy flash white when hit and then have it's color fade back to it's original texture. Can someone give tips on how to do this?
Thanks
Answer by Owen-Reynolds · Oct 25, 2013 at 08:01 AM
This is pretty hacky, but, you could oversaturate the main color. You can't do it in the Inspector (diffuse shader uses white 255/255/255 as the color for a normal-looking texture. You can darken that, but can't go any brighter.) But you can brighten it in code:
enemy1.renderer.material.color = new Color(3,3,3);
// blast of triple whiteness, which defeats even shading
The only problem is it only multiplies color, so pure black areas stay black, brown areas (like 100/60/0, no blue) will only turn bright yellow... but it might still look cool.
Then fade back to (1,1,1) however (I like coroutines, but a pain to learn.)
Would it also be possible to have it fade between two textures?
Anything fancy and you have to, I think, modify a shader.
For example, the current Unity Detail shader takes two textures and always multiples them together (since the second is assumed to be a "white with darker details" texture.) That could be changed to Lerp them by 0.5 (a standard blend.) Then that 0.5 could be changed to a float, which could be set in the material, and changed in a script for the blend. Then another version of the shader could be made with texture#2 replaced by white (which would do exactly what you first asked.)
That's all "easy," if you know simple shaders, which is less easy.
Your answer
Follow this Question
Related Questions
GUI.DrawTexture over screen 2 Answers
How to switch the texture being used by the material of the mesh renderer 1 Answer
Tracing in Unity3D 2 Answers
How to change a value in custom shader through script, C# 1 Answer
Render Transparent Geometry 1 Answer