I would like to call a coroutine function and return a value. To do so, I am calling function StartCheck() which calls a StartCoroutine(WaitStartCheck()). Below is a sample code to explain better what I’m trying to do:
private bool checkComplete = false;
private bool check = false;
bool StartCheck() {
checkComplete = false;
check = false;
StartCoroutine(WaitStartCheck());
while (!checkComplete) {
//some code
print(Time.deltaTime);
}
return check;
}
IEnumerator WaitSStartCheck() {
yield return new WaitForSeconds(5.0f);
if (condition)
check = true;
else
check = false;
checkComplete = true;
}
The problem is that the while loop is freezing Unity. How can I make this to work?
Thank you!