How can I change this variable for about 3 seconds then return to its original value?


This is what my playerSpeed is set to when I start ^^^

This is what I want to change it to when I collide with a certain object v v v


When I collide with a certain object i want to increase it by 9000, or change it to 10000, but only for a few seconds, can somebody please explain how I can do this. Sorry if this is too brief!

NOTE: Please ignore the SetText() void, it is for something else.

For future posts, please include code as text. After pasting the code, select it and use the 101/010 button. As for your question, you can do:

IEnumerator OnTriggerEnter(Collider other)
     playerSpeed = 10000;
     yield return new WaitForseconds(3.0f);
     playerSpeed = 1000;

Or you could do it by using the Invoke method :

//This will call the subReset_Player_Speed function in three seconds time.
//Place this line at the end of your trigger event.
Invoke ("subReset_Player_Speed", 3);

void subReset_Player_Speed() {
    playerSpeed = 1000;

You can check if an Invoke method is already running, which is useful if you triggered this event again within the 3 second time limit, at which point you could cancel the current Invoke and start it afresh.