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 :)
Answer by Paulo-Henrique025 · Oct 30, 2015 at 05:59 PM
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
Your answer
Follow this Question
Related Questions
Changing a variable value 2 Answers
Increase value by one each second [C#] 3 Answers
Is there a way to calculate elapsed Time in total? (Even when the App is closed etc.) 1 Answer
How to print variable? (C#) 1 Answer
Web Game Database 1 Answer