Stop Coroutine just doesn't work

Hello. I’m making a simple block breaker game, and I’m trying to add some new features. If I hit the block, there is 20% chance to get a boost from that block. So I’ve got 2 boosts:

  • Make the paddle bigger
  • Make the paddle smaller

Here is my code for them:

IEnumerator PaddleBigger()
    {
        Paddle.isBigger = true;
        paddle.transform.localScale += new Vector3(1, 0, 0); //megnyújtjuk
        gameObject.GetComponent<SpriteRenderer>().enabled = false;
        Paddle.minX = 1f;
        Paddle.maxX = 15f;

        yield return new WaitForSeconds(10);

        paddle.transform.localScale += new Vector3(-1f, 0, 0);
        Paddle.isBigger = false;
        Destroy(gameObject);
        Paddle.minX = 0.5f;
        Paddle.maxX = 15.5f;
    }
    IEnumerator PaddleSmaller()
    {
        Paddle.isSmaller = true;
        paddle.transform.localScale += new Vector3(-0.5f, 0, 0);
        gameObject.GetComponent<SpriteRenderer>().enabled = false;
        Paddle.minX = 0.25f;
        Paddle.maxX = 15.75f;

        yield return new WaitForSeconds(10);

        paddle.transform.localScale += new Vector3(+0.5f, 0, 0);
        Paddle.isSmaller = false;
        Destroy(gameObject);
        Paddle.minX = 0.5f;
        Paddle.maxX = 15.5f;
    }

So if I get the boost that makes the paddle bigger I resize the paddle, set the minX and maxX because of the Mathf.Clamp and start a Coroutine. After 10 secs its going to back to normal size, etc. The same as the paddlesmaller. So here is my question:

If I have a boost that makes my paddle bigger, and before it lasts and I get a paddle smaller boost how can I stop my PaddleBigger Coroutine? I’d like to do that, so my PaddleBigger Coroutine would stop, it means the size of the paddle will go to the normal size and suddenly starts the smallpaddle boost. I hope you understand what I’m trying to explain.

I was trying StopCoroutine function, but doesnt really seemed to work.

From inside a Corutine you can stop with:

yield break;

From outside you can stop with:

StopCorutine("MethodName")

Doesn’t seem to work none of them. I just don’t get what I am doing wrong.

Hi !

StartCoroutine(string)
//works with:
StopCoroutine(string)

and

Coroutine yourRoutine = StartCoroutine(IEnumerator)
//works with:
StopCoroutine(yourRoutine)

You can’t mixmatch both way to start and stop coroutines.