Color lerp once?

renderer.material.color = Color.Lerp (colorStart, colorEnd, 5*Time.deltaTime);

when I use this code, instead of fading from color 1 to 2 over (x) time, it blinks and never fully changes color?

What am I doing wrong/missing? Thanks!

Lerp's third argument is a number from 0 to 1 (inclusive) that indicates how close to the second argument it should go from the first.

If you want it to go completely to the colorEnd, you need to do something like

renderer.material.color = Color.Lerp(renderer.material.color, colorEnd, 0.1);

This will move the color of the material from where it is the first time you call it 10% of the remaining distance toward colorEnd each call.

Your mistake was restarting from colorStart each time it gets called.

Here is a simple script for everyone to use :wink:

var colorEnd: Color;
var Duration: float = 0.1;

function Update () {

gameObject.GetComponent(Renderer).material.color = Color.Lerp(gameObject.GetComponent(Renderer).material.color, colorEnd, Duration);