StopCoroutine not working at all

I have a basic StartCoroutine script and it works but in the StopCoroutine script it just doesn’t work at all

if (walkno == 1) {

            StartCoroutine (walk ());

        }
if (walkno == 0) {

            StopCoroutine (walk ());

        }

walkno is a public float and in the inspector it says it is at zero yet the coroutine doesn’t stop

@JDVDeisgn : Hi there, I think you have to stop it with string method name:

StopCoroutine("Walk");

Either as eses said or there are other ways:

  1. Save IEnumerator that StartCoroutine returned and StopCoroutine on it.
  2. yield break; from inside coroutine.

…Sorry, forgot to mention, to be able to stop coroutine like I mentioned, I think you also have start it like this too:

// not stopped
StartCoroutine(Test());
StopCoroutine("Test");

// Works
StartCoroutine("Test");
StopCoroutine("Test");
1 Like