【Unity】特定のcoroutineを停止させる
今までcoroutineを止めるときには
stopallcoroutine で止めていたのだけれど、めちゃくちゃなコードを書いているので自分でも何がどおなっているのかところどころ把握できず・・・いちいち全部止めてたら知らず知らずのうちにバグだらけ∧( 'Θ' )∧
public class MonoHelper : MonoBehaviour { private IEnumerator coroutine; public void DelayMethod(float time, Action action) { coroutine = _DelayMethod (time, action); StartCoroutine(coroutine); } private IEnumerator _DelayMethod(float time, Action action) { yield return new WaitForSeconds (time); action (); } public void StopCoroutine() { if(coroutine != null) StopCoroutine (coroutine); } }
ちょっと調べたらあっさり解決したけど、変数にしてしまえばえかったんか!