Cooldown timer that can pause

Hey…

So I’ve made this cooldown timer which works great

function StartTimer ()
{
	var t: float = 0.0f;
		
	while (t < 1)
	{
		t += Time.deltaTime / coolTimeMax;
		timer = Mathf.Lerp (0, 1, t);
		yield;
	}
	
}

The problem I have with it, is I cannot “pause” it mid timer. I’ve created a pause version of Time.time called “playTime”. And I’ve managed to pause the game by enabling or disabling playtime.

So I’m trying to create the same functionality of this StartTimer function, but using the playTime value. This version of a countdown timer uses Time.deltaTime.

Nevermind, after some lunch I solved this by just creating a float variable for Time.deltaTime, and used that instead.

so;

var getPlayTimeEnabled:         boolean = true;
var mockDeltaTime:				float 	= 0.0;


Function Update ()
{

   if (getPlayTimeEnabled)
	{
		mockDeltaTime = Time.deltaTime;
	}
	else
	{
		mockDeltaTime = 0.0;
	}
}

function StartTimer ()
{
	var t: float = 0.0f;
		
	while (t < 1)
	{
		t += mockDeltaTime / coolTimeMax;
		timer = Mathf.Lerp (0, 1, t);
		yield;
	}
}

I don’t know why I didn’t think of this sooner…