Question by
Follet · Mar 10 at 11:12 AM ·
c#coroutinewaitforseconds
Coroutine WaitForSeconds ignoring StopAllCoroutines... How can I do it?
Hello, I have a few "animations" based on activating ad deactivating images, and using WaitForSeconds in between. Then a "StopAllCoroutines" in a button, but when stopped, the coroutines won't stop if are suspended in waitforseconds:
public IEnumerator IEQuickJumpTuto;
void Start { IEQuickJumpTuto = QuickJumpTutoCoroutine(); }
//On button press I do
public void QuickJumpTutoButtonPress()
{
StartCoroutine(IEQuickJumpTuto);
}
public IEnumerator QuickJumpTutoCoroutine()
{
PauseEnter();
explanation.text = instruccionsTXTlist[4];
boolsTutolist[4] = true;
//This are images that compose the little animations
images[0].gameObject.SetActive(true);
yield return new WaitForSeconds(1);
images[0].gameObject.SetActive(false);
images[1].gameObject.SetActive(true);
yield return new WaitForSeconds(1);
images[1].gameObject.SetActive(false);
images[0].gameObject.SetActive(true);
yield return new WaitForSeconds(1);
images[0].gameObject.SetActive(false);
images[1].gameObject.SetActive(true);
yield return new WaitForSeconds(1);
images[1].gameObject.SetActive(false);
if (boolsTutolist[4]) //This is a bool that turns false the HideTutos() IsPressed
{
StopCoroutine(IEQuickJumpTuto);
IEQuickJumpTuto = QuickJumpTutoCoroutine();
StartCoroutine(IEQuickJumpTuto);
}
else
{
HideTutos(); //My temporal fix, already called with the "Close Tutorial Button"
}
}
//This is called with a button to close the tutorial
public void HideTutos()
{
StopAllCoroutines();
explanation.text = " ";
for (int i = 0; i < images.Count; i++)
{
images[i].gameObject.SetActive(false);
}
for (int i = 0; i < boolsTutolist.Count; i++)
{
boolsTutolist[i] = false;
}
bb.PauseExit();
}
So what happens is the "tutorial widow" opens, the animation is running, but if the HideTutos() is called while inside a WaitForSeconds, the coroutine dosen't stop, it keeps going until it reaches the end.
Comment