Start timer with trigger


I need to start a timmer when a boolean is true, but I can’t make it work. Any help?

Thanks in advance!

#pragma strict
var burn : boolean;
var col : Color = Color.white;
private var timer : float;

function Update() {
	timer = Time.deltaTime;
		col = Color.Lerp(Color.white,, timer);
	renderer.material.color = col;

function ResetTimer() {
	timer = 0.0;

The problem with your code is that you use if(burn) only. If you do not want to restart the timer every frame again (which basing on the code could happen), you would need to have an

if (burn && timer <= 0.0)

To ensure that float inaccuracy does not hit you, I would set the timer to -1 when its reset to clearly mark it as ‘not running’, but you could instead use a second bool to track the timer being ‘running’ independent of using its timer value