Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Dantevw1986 · Feb 03, 2012 at 09:12 AM · messagebox

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.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

4 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by CorruptedHeart · Feb 03, 2012 at 03:27 PM

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CorruptedHeart · Feb 06, 2012 at 03:40 PM 0
Share

I'll do a little code clean up and put it on the Asset Store

avatar image CorruptedHeart · Feb 09, 2012 at 05:52 AM 0
Share

It's now available on the Asset Store http://u3d.as/content/corrupted-smile-studio/message-box/2Eo

avatar image
3

Answer by HaimBendanan · Dec 31, 2016 at 01:27 PM

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

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
2

Answer by sirjoan620 · Apr 02, 2017 at 12:52 PM

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.");


Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Maxence_Marchand · May 29, 2018 at 12:22 PM 1
Share

EditorUtility only works within the editor, it will create an error when you will try to build the application.

avatar image
0

Answer by ByteSheep · Feb 03, 2012 at 09:53 AM

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 :)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Is there an easy way to create MessageBoxes? 2 Answers

Can I deactivate a messagebox without any scripting? 1 Answer

Let Sound Clip wait for x seconds before sounding ? 1 Answer

[En & Fr] Show a message on the screen - Faire apparaître un message sur l’écran 1 Answer

GUI Message Box 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges