unity3d - Unity 5.0.1 Completely Stopping a Coroutine -
alright running slight issue, basically, have coroutine contains for-loop. can call stopcoroutine , startcoroutine methods successfully, of course, pauses , unpauses coroutine. there way stop , restart it? end-goal here able start coroutine, kill @ user's discretion, , restart beginning time, @ user's discretion. accomplishable? thanks.
to "rewind" coroutine, call coroutine method again same parameters. if want save these parameters, can use closures:
public class coroutineclosureexample : monobehaviour { private system.func<ienumerator> createcoroutinefactory(int someint, float somefloat) { return () => coroutineyouwant(someint, somefloat); } private ienumerator coroutineyouwant(int someint, float somefloat) { for(int = 0; < someint; i++) { yield return new waitforendofframe(); } } private system.func<ienumerator> m_currentcoroutinefactory; private ienumerator m_currentcoroutine; public void setcoroutineparameters(int someint, float somefloat) { m_currentcoroutinefactory = createcoroutinefactory(someint, somefloat); } public void restartcurrentcoroutine() { if (m_currentcoroutine != null) { stopcoroutine(m_currentcoroutine); m_currentcoroutine = null; } if (m_currentcoroutinefactory != null) { m_currentcoroutine = m_currentcoroutinefactory(); startcoroutine(m_currentcoroutine); } } }
Comments
Post a Comment