Can i instant finish a Coroutine ?

i see an IEnumorator are very useful but in this case i dont know there are any solution?

    IEnumerator IEName()
    {
        Do A;
        yield return new WaitForSeconds(5f);
        Do B;
    }

so i wonder if i use StartCoroutine(IEName()), how can i stop and break this Coroutine(if done “Do a”, just “Do a” not “Do b”) or finish it(instant “Do b”). Thanks for read, hope u help me :slight_smile:

Hello, @Tu-Le!

Please do this: save your coroutine in the variable

var coroutine = StartCoroutine(IEName());

then when you would like to Stop, please write:

Stop(coroutine).

Also you can break the coroutine inside the coroutine, for example:

if (condition)    
{
  yield break;
}