- Home /
How to check if any coroutines are running in a class
I have a class where the the a coroutine function which is getting called multiple times. I would like to know how to check whether all the coroutines are done or not. Here is my example:
class something { void CallCoroutine(int param) { StartCoroutine(func(param)); }
IEnumerator func(int param)
{
while(somecondition is true) //This condition returns returns value for sure. Either true or false
yield return WaitForEndOfFrame();
yield return null;
}
}
Here the function CallCoroutine() called for some 15 times.
I want to check if any coroutines are running or not. Please give me suggestions how to fix this.
Thank you in advance.
Well... Thanks for your reply.
This is working exactly how I am expecting.
Great. I have converted that into the answer. Thanks for letting me know.
Answer by tomekkie2 · Jan 06, 2015 at 08:35 AM
Define an int control variable in the script for the number of coroutines currently running. And a boolean variable for any coroutine currently running.
bool running = false;
int runningCor = 0;
IEnumerator func(int param)
runningCor++;
{
while(somecondition is true) //This condition returns returns value for sure. Either true or false
yield return WaitForEndOfFrame();
runningCor--;
running = (runningCor== 0);
yield return null;
}
Let me know if it works, so I could turn it into an answer.