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;
}
}