I think I need help with Coroutines:
When the player dies, I call a Coroutine to inform the overall Game Administration object that the player is dead:
StartCoroutine(BattleInstance.instance.PlayerKilled());
In there I do a bunch of administrative things like stopping the spawning of enemies and more (which work fine).
public IEnumerator PlayerKilled()
{
Cursor.visible = true;
WaveManager.instance.PauseBattle();
if (_costToRevive != 0)
{
yield return StartCoroutine(BattleViewController.instance.ShowContinuePopup(_countdownToRevive, _costToRevive));
}
yield return StartCoroutine(EndGame());
}
My problem is with the coroutine I call to show my “Continue?” pop up:
yield return StartCoroutine(BattleViewController.instance.ShowContinuePopup(_countdownToRevive, _costToRevive));
Theoretically after that one is finished (basically once the continue timer has run to 0, there’s supposed to be the coroutine started which handles my scene switching, player saving and some other administrative things:
yield return StartCoroutine(EndGame());
Unfortunately my code never gets there. From what I was able to see so far when my ShowContinuePopup coroutine ends, it just ends… and the PlayerKilled coroutine doesn’t continue.
Here’s the last coroutine that finishes:
public IEnumerator ShowContinuePopup(int timer, int? cost = null)
{
yield return StartCoroutine(_continuePopup.Countdown(timer, cost));
_continuePopup.HideContinuePopUp();
}
I have tried a bunch of things including adding a ‘yield return null;’ in the end of that last method or making the HidePopUp method a coroutine and yield for that… nothing helps. When I set my _costToRevive to 0 to bypass the ShowContinuePopUp coroutine, it works, so it must be somewhere after hiding the popup and calling the EndGame coroutine… But there’s nothing there.
Any ideas why?