How to wait click on button in my MessageBox analogue?

Hi!

I’m trying to implement my own analogue of .NET MessageBox but I have a problem. My method ShowDialog() returns variable with DialogResult type:

98706-screenshot-1.png

How to wait for the button to be pressed in MessageBox before returning DialogResult? I alredy tried to use coroutines, but it isn’t work because it runs waiting methods parallel with other methods. implementation of MessageBox.ShowDialog():

P.S. I do not want to pass a delegate as a parameter to ShowDialog().

P.S.S. In C# I can loop this method, but in Unity it doesn’t work: Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(delegate { }));

  1. Leave the button open.
  2. Do calculations.
  3. Close the button, when a user presses down on it.

Last step is done by adding a box collider (2d/3d) to a button.