Add time to the clock with pickup

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

the easiest way to do this is to create a new public float or int and do something like this:

public float CurTime = 10.0f;
public float AddTime = 5.0f;

void Update() {
CurTime = CurTime + AddTime;
}

if you want to know how to make the player pick up the object use a ontriggerenter function

You want the code on your player:

function OnTriggerEnter(collision : Collision) {
  if(collision.tag == "timerObject") {
    Destroy(collision.gameObject);
    gameObject.GetComponent(TimerCountdown).currentTime += 10;
  }
}

So to explain:

Your time extending object have to have tag named “timerObject” (you can thange this ofcourse). When collision happens, you first check if the object you collided had that tag. If it did, you destroy the object and extend time. This code is ment to be on script other than TimerCountdown but on the SAME OBJECT, because you search for the TimerCountdown script on it.

You could aswell had it all in one script.

Someone please check this. I never did anything in Unityscript.