Skip to content

Instantly share code, notes, and snippets.

@renaudbedard
Created September 2, 2016 14:31
Show Gist options
  • Save renaudbedard/14e69379f34d42d3ae109047ad05c649 to your computer and use it in GitHub Desktop.
Save renaudbedard/14e69379f34d42d3ae109047ad05c649 to your computer and use it in GitHub Desktop.
Nested coroutine stop problem
class Foo : MonoBehaviour
{
Coroutine m_coroutine;
public void StartThing()
{
m_coroutine = StartCoroutine(ParentCoroutine());
}
public void EndThing()
{
if (m_coroutine != null)
{
// this stops the parent coroutine, but any ChildCoroutine that was in process will still complete
StopCoroutine(m_coroutine);
m_coroutine = null;
}
}
public IEnumerator ParentCoroutine()
{
yield return ChildCoroutine(1);
yield return ChildCoroutine(2);
yield return ChildCoroutine(3);
}
public IEnumerator ChildCoroutine(float _varyingInput)
{
// do stuff based on input
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment