-1
\$\begingroup\$

I have the following coroutine:

    public IEnumerator EndGame() {
    //StopAllCoroutines();
    GamePauseController.instance.UnfreezeTime();
    DisintegratorModalController.instance.ignoreBorderDisin = false;
    ignoreBorderEndGame = true;
    StartCoroutine(CubeBehavior.instance.DestroyCubesGameOver());
    StopBackgroundMusic();
    DisableCubeSpawner();
    CubeBehavior.instance.ClearSelectedCubes();
    ScoreManager.instance.StopCountingScore();
    GameDataManager.instance.SaveHighScoreAndDisintegrators();
    ScoreManager.instance.SaveScoreToLeaderboard();
    LightColorManager.instance.WhiteFadeToHeartbeat();

    while (!CubeBehavior.instance.allCubesDestroyed) { // Wait for all the cubes to be destroyed before continuing
        yield return null;
    }

    Debug.Log("Working");
    StartCoroutine(HUDController.instance.HideHUD());
    StartCoroutine(GameResultsController.instance.ShowResultsMenu());
    MenuParticles.instance.Show();
}

After the bool check the code below it doesn't execute when it should. What is the issue here?

\$\endgroup\$
  • \$\begingroup\$ When do you expect it to execute? Using the yield statement will make this function pause, and resume on the next frame. It will not execute like a standard function. \$\endgroup\$ – jgallant May 16 '16 at 14:40
  • \$\begingroup\$ Do you call the function by using StartCoroutine(EndGame()) ? \$\endgroup\$ – Sheikz May 17 '16 at 14:32
  • \$\begingroup\$ @Sheikz Yes I did \$\endgroup\$ – Milen May 18 '16 at 17:10
  • \$\begingroup\$ When it should - you need to tell us what you expect by when. We are not psycics. You need to explain how the allCubesDestroyed changes, what interacts with them. \$\endgroup\$ – S. Tarık Çetin Sep 27 '16 at 9:40
  • \$\begingroup\$ @S.TarıkÇetin The problem is resolved... \$\endgroup\$ – Milen Sep 28 '16 at 6:56
0
\$\begingroup\$
  1. CubeBehavior.instance.allCubesDestroyed remains false.
  2. You're calling StopAllCoroutines somewhere else in the code, before this one can complete
  3. There's some other error that your code here and explanation haven't revealed.

Attach the debugger, break on execution of the yield, check your variables at runtime to ensure they're doing what you expect. Step through your code visually to ensure it's doing what you want. And other basic troubleshooting debugging steps.

\$\endgroup\$
  • \$\begingroup\$ 1. The bool turns to true, I've put a debug log to check that. 2. No other StopAllCoroutines in the code save the one I've commented above 3. Not sure about that \$\endgroup\$ – Milen May 16 '16 at 16:19
  • \$\begingroup\$ Put a print("Still waiting..."); or something into the while loop just so you can see if it breaks. \$\endgroup\$ – GMR516 Sep 27 '16 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.