I have a nice countdown script from a tutorial. I would like to create pickup that adds time to the clock. Here is my Timer script named “TimerCountdown”. What would the script look like that would be attacked to the item being picked up?
// the textfield to update the time to
private var textfield:GUIText;
// time variables
public var allowedTime:int = 100.0;
private var currentTime = allowedTime;
function Awake()
{
// retrieve the GUIText Component and set the text
textfield = GetComponent(GUIText);
UpdateTimerText();
// start the timer ticking
TimerTick();
}
function UpdateTimerText()
{
// update the textfield
textfield.text = currentTime.ToString();
}
function TimerTick()
{
// while there are seconds left
while(currentTime > 0)
{
// wait for 1 second
yield WaitForSeconds(1);
// reduce the time
currentTime--;
UpdateTimerText();
}
Application.LoadLevel (5);
}