Wait in unity(coroutine not working)
Hi, I am trying to make game wait for a number of seconds when the player gets a powerup. I have this drink object so when the player collides with this drink, the user gets a power-up. I want the game to wait for 5 seconds before the powerup is gone. I tried using Coroutines but they don't work for me. here is some of my code:
inside my OnTriggerEnter: if (coll.collider.tag == "powerUpDrink") { activePowerup = true; DestroyObject(coll.gameObject); GetComponent().color = Color.red; rage_text.SetActive(true);
//Wait for 5 seconds
StartCoroutine(wait(5f));
rage_text.SetActive(false);
GetComponent<Image>().color = Color.green;
DestroyObject(coll.gameObject);
activePowerup = false;
}
this is outside of OnTriggerEnter(): IEnumerator wait(float sec){ yield return new WaitForSeconds(sec); }
thanks in advance :)
Your answer
Follow this Question
Related Questions
reload script assemblies is VERY Slow. 1 Answer
Noobie question: wait a random time 1 Answer
How do make an object appear and disappear after t seconds? 1 Answer
How to use IEnumerator? Pls help! 1 Answer
How to delay an action in Untiy 1 Answer