Trouble with Co routines & WaitForSeconds
So mega newbie here, first time posting here. Making a small 2d game and want to have a coroutine to trigger a powerup on and off again after the coroutine. Now I don't have a problem calling the coroutine but the problem is that it seems to not run any of the subsequent lines after the WaitForSeconds
. I've tried WaitForSecondsRealtime
and did not work either. I have used this code before in a tutorial, but for some reason it won't work here. Once again, the lines of code within the IEnumerator
are not running, I believe something might be conflicting or halting the time but I'm not sure what it could be. Here is my code:
void OnTriggerEnter2D ( Collider2D collision )
{
if( collision.name == "Woman" )
{
Debug.Log("player has absorbed the crystal");
Destroy(gameObject);
StartCoroutine("PowerUpTimer");
//set value for the powerup
// set some alert to notify that woman has the powerup
//set the special bar to fill and react to the use
}
}
IEnumerator PowerUpTimer ()
{
Debug.Log("woman has special");
womanCombatScript.hasSpecial = true;
yield return new WaitForSecondsRealtime(2);
Time.timeScale = 0;
Debug.Log("the waitforsecondswentthrough");
womanCombatScript.hasSpecial = false;
Debug.Log("woman no longer has special");
}
Your answer
Follow this Question
Related Questions
Yield WaitForSeconds doesn't work! 1 Answer
Add an value to a variable after 2 seconds 1 Answer
Trying to make dash energy system... 1 Answer
Yield wait for seconds not working at all? 2 Answers
yield ends method 0 Answers