Unity 3D Game Engine – Materials – Fade Between 2 Base Colors
1. MAIN TOP MENU> Gameobject> Create Other> Cube
2. Hierarchy, select the Cube> Inspector> materal slot, select Shader: Diffuse
NOTICE: the script will fade between ‘Shader> ‘Main Color’ values, you HAVE TO REMOVE all textures if you want to see ‘Main Color’!
3. Add to the Cube Fade.JS
#pragma strict // Fade the color from red to green // back and forth over the defined duration var colorStart : Color = Color.red; var colorEnd : Color = Color.green; var duration : float = 1.0; function Start () { } function Update () { var lerp : float = Mathf.PingPong (Time.time, duration) / duration; renderer.material.color = Color.Lerp (colorStart, colorEnd, lerp); }
4. Done!