My Coroutine Ignores the Boolean

In another script, a bool controls when this coroutine starts and stops:

IEnumerator SpawnWaves ()
	{
        if (SceneManager.GetActiveScene().buildIndex == 7)
        {
            shrinkStage = true;
        }
        if (shrinkStage == false)
        {
            yield return new WaitForSeconds(startWait);
            while (true)
            {
                for (int i = 0; i < hazardCount; i++, fireCometCount++)
                {
                    //var asteroidY = Random.Range (Mathf.RoundToInt(-spawnValues.y), Mathf.RoundToInt(spawnValues.y));
                    //var collectY = Random.Range (Mathf.RoundToInt(-spawnValues.y), Mathf.RoundToInt(spawnValues.y));
                    var random = Random.Range(0, 3) + 1;

                    //Debug.Log (Mathf.RoundToInt(-spawnValues.y) + " - " + Mathf.RoundToInt(spawnValues.y));

                    //if (asteroidY == collectY) {
                    if (random == 1)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(hazard, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnWait);
                    }
                    else if (random == 2)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(collectable, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnWait);
                    }
                    if (fireCometCount == 20)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(comet, spawnPosition, spawnRotation);
                        fireCometCount = 0;
                        yield return new WaitForSeconds(spawnWait);
                    }
                }

                yield return new WaitForSeconds(waveWait);

                if (gameOver)
                {
                    restartText.text = "Restart";
                    restart = true;
                    //break;
                }
            }
        }
    }

But in another script this bool is completely ignored:

    IEnumerator SpawnShrinkWaves()
    {
        if (gameController.waveTransition == false)
        {
            while (true)
            {
                for (int i = 0; i < hazardShrinkCount; i++)
                {
                    var random = Random.Range(0, 12) + 1;

                    if (random == 1 || random == 2 || random == 3 || random == 4)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(hazard, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnTime);
                    }
                    else if (random == 5 || random == 6 || random == 7 || random == 8)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(collectable, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnTime);
                    }
                    else if (random == 9 || random == 10)
                    {
                        Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(shrinkHazardOne, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnTime);
                    }
                    else if (random == 11 || random == 12)
                    {
                        Vector3 spawnPosition = new Vector3(11, -0.2f, -2);
                        Quaternion spawnRotation = Quaternion.identity;
                        Instantiate(hazardBarrier, spawnPosition, spawnRotation);
                        yield return new WaitForSeconds(spawnTime);
                    }
                }
            }
        }
    }

I know it’s not the bool itself, because this works in the same script:

void SpawnBarrier()
    {
        if (gameController.waveTransition == false)
        {
            Vector3 spawnPosition = new Vector3(11, -0.2f, -2);
            Quaternion spawnRotation = Quaternion.identity;
            Instantiate(hazardBarrier, spawnPosition, spawnRotation);
        }
    }

So why does the Coroutine ignore the bool? Why doesn’t the loop only start when waveTransition == false? I want my Coroutine to play, and stop during the wave transition, then play again. By the way, I’ve never got StopCoroutine to work. I’ve always stopped coroutines with a boolean, which has worked until now! I can’t figure out what’s different.
If anyone could help me that would be much appreciated.

OK, so I’ve achieved my goal by changing the code to this:

IEnumerator SpawnShrinkWaves()
    {
        for (int i = 0; i < hazardShrinkCount; i++)
        {
            var random = Random.Range(0, 12) + 1;

            if (random == 1 || random == 2 || random == 3 || random == 4)
            {
                Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazard, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnTime);
            }
            else if (random == 5 || random == 6 || random == 7 || random == 8)
            {
                Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(collectable, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnTime);
            }
            else if (random == 9 || random == 10)
            {
                Vector3 spawnPosition = new Vector3(spawnValues.x, Random.Range(-spawnValues.y, spawnValues.y), spawnValues.z);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(shrinkHazardOne, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnTime);
            }
            else if (random == 11 || random == 12)
            {
                Vector3 spawnPosition = new Vector3(11, -0.2f, -2);
                Quaternion spawnRotation = Quaternion.identity;
                Instantiate(hazardBarrier, spawnPosition, spawnRotation);
                yield return new WaitForSeconds(spawnTime);
            }
            if (gameController.waveTransition == true)
            {
                hazardShrinkCount = 0;
                yield return new WaitForSeconds(10f);
                hazardShrinkCount = 30;
            }
        }
    }

By adding the bool within the loop and checking for waveTransition == true, I’ve made the hazardShrinkCount = 0 so that nothing spawns. This lasts for 10 seconds (the length of inactivity during the wave transition), and then hazardShrinkCount returns to 30 to continue spawning as the new wave begins.

Now, this means the coroutine doesn’t actually pause, it just appears so when playing the game. It’s not exactly what I want but at least it works.

My question still stands, though. How do you pause/play a coroutine using a bool? If this is impossible, how do you pause/play a coroutine at all? And if THAT is impossible, why can’t you pause/unpause a coroutine? As far as I’m aware, you can only break (stop coroutine) and then can never start it again.