Change a variable value for 5 seconds

Hi there

I would ask for your help in this script i’m doing.It’s a basic double points script and i would like it for when someone presses the button my x variable would change from 1 to 2 for five seconds and then, after those five seconds have passed, it would flip back to 1.

Help is appreciated, have a nice day :slight_smile:

You can use Coroutines to achieve this:

IEnumerator EnableTimedBonus()
{
        bonus = 2;
        yield return new WairForSeconds(5.0f);
        bonus = 1;
}

To call it use the StartCoroutine function, you can learn more about Coroutines here:
Coroutines - Learn Unity