Burning Effect Lerp Not werking

Hello, I am trying to make a burning effect, this is my code:

var lerpedColor : Color = Color.white;
var Timer = 5.0;
	
function Update() 
{
gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.white, Color.black, Time.time /Timer);
}

When placed on a cube for example, it works great lerping down in 5s, but if I then place it on another cube with the game still runnning it is directly black, and not going from White to black.

I realise that it is in memory somewhere but how can I reset it?

Thanks.

Just keep track of the value of Time.time at the beginning of the lerp on a specific object. The problem you are experiencing is due to the value of Time.time already being beyond the duration of your lerp when you assign it to the second object, storing the start time of the lerp for that object allows you to essentially “reset” the time value for the purposes of your lerp calculation.

float start = 0.0f;

void StartLerping()
{
start = Time.time;
}

void Update()
{
Color lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start) / duration); 
}

Thanks a lot everybody, using all of your info I done it like this:

var lerpedColor : Color = Color.white;
var duration = 30.0;
var start = Time.time;

function Update() 
{
	if (start == 0.0f) 
	start = Time.time;
	gameObject.renderer.material.color = lerpedColor = Color.Lerp(Color.white, Color.black, (Time.time - start ) /duration);

}

Thanks khalladay for pointing out exactly what was going on :wink: