This Delay function I wrote is called after a button is pressed. When it runs, Unity crashes and doesn’t even print the debug statement inside the while loop:
private bool delayOver;
public void Delay(float seconds)
{
delayOver = false;
StartCoroutine(DelayCoroutine(seconds));
while(!delayOver)
{
Debug.Log("in loop...");
}
Debug.Log("delay is over, do next thing");
}
private IEnumerator DelayCoroutine(float seconds)
{
yield return new WaitForSeconds(seconds);
delayOver = true;
}
Note: I am familiar with coroutines and the Invoke function, I have used both of them in the conventional way in games I’ve made. In this case I need to do it differently, like the code above, without it crashing.