- Home /
How to Stop C# Coroutine
I need to kill a coroutine in C# that was started with:
StartCoroutine(MyTimer(x));
How can I do this?
any number of ways, try a global boolean flag or you can save the instance of the function and out right destroy it.
No, I just consider this internet clutter because the answer is so easy to find, and he asked it at the same time, on the forum. I read the FAQ, though, and it says that this type of question is okay, so I deleted my snarky answer. Doesn't mean I'm personally okay with it.
Yes, I didn't ask the question in for forum, precisely because it was downvoted here. I actually ran a thorough Google search of the Unity forums for an answer to this question, but there's surprisingly little advice for stopping a c# coroutine with the StopCoroutine method. tomvds provided the best answer on the forum:
StartCoroutine("$$anonymous$$yTimer", x); StopCoroutine("$$anonymous$$yTimer");
I'm sure some folks besides myself will find that useful both here and on the forums.
Err... meant to say: I "DID" ask the question on the forums...