Hello everyone - I suspect this is a quick question. I have attached some code below. I would like to be able to use this same countdown timer code across a bunch of different levels but only modify the “allowedTime” variable in the inspector. As of right now I can’t get anything I put in the inspector to update the public variable. It always locks to 90 seconds. I have tried removing the “=90” part in the script but then the timer just defaults to 0.
Any thoughts/ suggestions how to fix would be appreciated.
// the textfield to update the time to
private var textfield:GUIText;
// time variables
public var allowedTime:int = 90;
private var currentTime = allowedTime;
function Awake()
{
// retrieve the GUIText Component and set the text
textfield = GetComponent(GUIText);
UpdateTimerText();
// start the timer ticking
Tick();
}
function Tick()
{
// while there are seconds left
while(currentTime > 0)
{
// wait for 1 second
yield WaitForSeconds(1);
// reduce the time
currentTime--;
UpdateTimerText();
}
// game over
print("Game Over");
}
function UpdateTimerText()
{
// update the textfield
textfield.text = currentTime.ToString();
}