Stopping Couroutine
Hi all. I have a couple of coroutines that I just can't get to stop. I'm no pro but I've read so many examples and other peoples problems around this now I'm going crazy. Can someone tell me what I'm doing wrong? I've tried a bunch of different options to the code below like: Not caching the CR when starting/stopping it. Starting/Stopping CR with name string. I've used "true" in the while loop and tried to break out other ways.
Everything is in the same MonoBehaviour in the same file. I see gameOver gets set to true in logs.
The Move() should stop executing both from gameOver going true and from stopping the CR's right?
private float moveDelay = 0.4f;
private bool gameOver = false;
private IEnumerator moverCoroutine;
void Start() {
moverCoroutine = Mover();
StartCoroutine(moverCoroutine);
}
void Update()
{
if (gameOver)
{
StopCoroutine(moverCoroutine);
StopAllCoroutines;
}
}
private IEnumerator Mover()
{
while (!gameOver)
{
Move();
yield return new WaitForSeconds(moveDelay);
}
}
Your answer
Follow this Question
Related Questions
c# shooting problem (probably pretty simple) 2 Answers
I can't figure out how to get the audioClip of a movieTexture in code. 0 Answers
c# How to delay code for animator animation to finish 2 Answers
"Can't add script behaviour AICharacterControl. The script needs to derive from MonoBehaviour!" ? 2 Answers
Can't stop a Coroutine with a Coroutine Reference ?! 0 Answers