Need to stop a coroutine in C# that was started like this:
StartCoroutine(MyTimer(x));
How?!!! :?
Need to stop a coroutine in C# that was started like this:
StartCoroutine(MyTimer(x));
How?!!! :?
Write the coroutine such that it automatically drops out if a certain variable is set (or unset). Then set/unset the variable to end the coroutine.
Otherwise, AFAIK, you can only end all coroutines on a particular object, not specific coroutines.
I can’t believe we’re so limited in this department. Setting/Unsetting variables gets complicated really fast when you have several coroutines running.
You can’t if you start it like that.
You can stop it if you start it like this:
StartCoroutine("MyTimer", x);
StopCoroutine("MyTimer");
State Variables are normally the better idea because the coroutines then will exit at clearly defined points.
with stop you stop it just somewhere and that will not always end all that nice. For example fucking up a coroutine that does an async operation, especially WWW, will become a serious problem
I didn’t know the following worked in C#:
StartCoroutine("MyTimer", x);
Thanks for that tidbit! @ Dreamora: I see your point, but in this case I’m stopping a basic MoveTo lerp, so I don’t anticipate that problem.
If you use StopAllCoroutines, then you can stop a coroutine whether it was started with a string, or the usual way. Of course that’s not what you want if you have more than one coroutine on that behavior and don’t want to stop them all. On the other hand it is confined to that behavior (and not all coroutines, everywhere), so it can be useful.
–Eric