When two co-routine is running.Then how to stop first co-routine?
GLOBALS.stableTime = 5;
IEnumerator StableWaittingTime ()
{
yield return new WaitForSeconds (1f);
if (GLOBALS.stableTime == 0) {
GameManager.instance.LevelFaildMethod ();
} else {
GameManager.instance.stableWaittingTime.text = GLOBALS.stableTime.ToString ();
GLOBALS.stableTime--;
StartCoroutine ("StableWaittingTime");
}
}
Take a look at this:
It’s not my work, but I have tested it and is really helpful.
Kiwasi
3
Two methods come to mind
The best method I can suggest is using the string form of StartCoroutine. Then you can call StopCoroutine directly.
StartCoroutine("StableWaittingTime");
StopCoroutine("StableWaittingTime");
The other method is build you coroutine so is automatically aborts when the condition is satisfied.
Hardik
4
You can also use yield break
for stop co-routine
IEnumerator DoCheck() {
yield return new WaitForSeconds (1f);
//Do your stuff here
yield break;
}