How to make a messagebox in Unity

Im im very new to unity, and started off with some tutorials. Also i do a simple test project to get to understand the basic stuff.

Now what i try to do, is make a messagebox pop up when the ESC key is pressed.

if it would have been a win application, i would have done something like this in C#:

	if (Input.GetKeyDown(KeyCode.Escape)) 
	{
		var message = "exitmessage";
        var title = "exitTitle";
        var result = MessageBox.Show(
            message,                    // the message to show
            title,                      // the title for the dialog box
            MessageBoxButton.YesNo,     // show two buttons: Yes and No
            MessageBoxImage.Question);  // show a question mark icon

        // lets see what has been pressed
        switch (result)
        {

            case System.Windows.MessageBoxResult.Yes:   // Yes button pressed
                 Application.Quit();
                break;

            case System.Windows.MessageBoxResult.No:    // No button pressed
                break;

            default:                 // Neither Yes nor No pressed (just in case)
                MessageBox.Show("Oh noes! What did you press?!?!");
                break;
        }

	}

But it is no Win app, it is Unity.
Now, i dont have a clue how i should make something like this in unity.
Could someone point me in the right direction with a sample, or a website or something that would help me?

thank you in advance.

I started working on a basic Unity port of the .Net MessageBox class. It uses very similar function calls, however it works with callbacks instead of working entirely within the same calling method like the .net version works.

Here’s a basic layout of how it would look when calling it.

public MessageBoxButtons buttons = MessageBoxButtons.YesNo;
public MessageBoxIcon icon = MessageBoxIcon.None;
public MessageBoxDefaultButton defaultButton = MessageBoxDefaultButton.Button1;

void Start()
{
    MessageBox.Show(Callback, "Hello World!", "Hello", buttons, icon, defaultButton);
}

void Callback(DialogResult result)
{
    Debug.Log(result.ToString());
}

http://forum.unity3d.com/threads/122455-MessageBox

You can use unity GUI, for instance:

function OnGUI() {

GUI.Box(Rect(0,0,Screen.width/2,Screen.height/2),"This is the text to be displayed");

}

Here’s a good page with the unity GUI basics.
You can replace the text with a string variable that can be changed and you can set the gui to only display when you have pressed a certain button etc, but I won’t get into that now.
If you google it or search on this site I’m sure you’ll find plenty of results/similar questions :slight_smile:

I made a message box during the development of my game in Unity, feel free to use it:
simple message box for unity - github

This is an old question, but I’m answering because I see it in Google’s search results.

EditorUtility can help in this situation.

if(EditorUtility.DisplayDialog(title,message, "Yes", "No" ))
    print("Pressed Yes.");
else
   print("Pressed No.");