Timer counts down unwanted

Hello,

I’m creating a simple platformer game. In my game you can purchase add-ons. But i want to limit the time you can use these add-ons.

The probem is when i hit the button ‘equipment’ the timer looks like it’s already counting downwards even if i didn’t pressed the button.

For example: My begin time is 15 and my end time is 0.

I start the game for 5 seconds. Then i press the button. Normally the time should count downwards starting at 15. But that doesn’t happens. It starts and 10 and keeps counting downwards until 0.

Here are my scripts:

In my basic player script I have this:

static var GJUnlocked = false;

// GJ just means gravity jammer. That's one of the add-ons.

function Update()
{
if(Input.GetButtonDown("Equipment"))
  {
  GJUnlocked = true;
  }
}

And this is my timer script attached to a gui text:

// eq means equipment. It's just a name i gave the variable.

var eqEndTime : float;
var eqBeginTime : float;
static var timeLeft :int;

function Start()
{
  
    eqEndTime = Time.time + eqBeginTime;
	guiText.text = eqBeginTime +"";
	
}

function Update()
{

if(MoveAround.GJUnlocked == true)
	{
	
		timeLeft = eqEndTime - Time.time;
		if (timeLeft < 0) timeLeft = 0;
		guiText.text = "Time left: "+timeLeft;
	}
}

You 're setting the eqEndTime variable when your script starts. At this point your time is aways 0, so eqEndTime is aways 15 (assuming that’s the value of eqBeginTime). You should set the variable only at the moment you purchase the add-on.

Time.time is the time since your game launched. So even when your object is not unlocked Time.time is still progressing. Try setting timeLeft once in the Start function and then inside your if statement in the Update function use delta time instead. Something like:

timeLeft -= Time.deltaTime;