Need to make synchronous delay function (not running in parallel like coroutine or Invoke)

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.

@unity_gaC7Q2kf-Uf7uQ

I think you should not block the main thread with a while loop.

private IEnumerator DelayCoroutine(float seconds)
     {
         Debug.Log("Before waiting"); //here you have what you want to execute before waiting
         yield return new WaitForSeconds(seconds);
         Debug.Log("delay is over"); //Here you have what should be executed after waiting.
     }