• 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
Question by RSunity · Dec 08, 2010 at 01:16 AM · messagebox

GUI Message Box

Hi, I've been having some trouble creating a GUI Message Box. Basically, I want to make a script for the message box, but be able to call this message box from a different script.

For example,

I would use this on a different script:

MessageBox("Text goes here.");

or something like that but it would be getting the message box from the original script.

Comment
Jesus_Freak

People who like this

1 Show 0
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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Jesus_Freak · Dec 08, 2010 at 01:27 AM

you vould put on this script if you want only words but can convert it into a button easily if you want:

//the name of this script this following code is in is important! will be //refered to as "Message" by me. so you could replace Message in the next code with your actual name for it. static var Str : String;

function OnGUI() { GUILayout.Label(Str); }

and that would automaticlly make the string ubneditable through the inspector (making it 100% program-changable and programming-changable only!) but it displays the text as a preset label.

in another script you could do

function Update()
{
 if(Input.GetKeyDown(KeyCode.delete)) // when the delete key is pressed
 {
  Message.Str = "Deleted"; // example word to be displayed.
 }
}

i hope that helps you, and that if this isn't what you wanted, that it at least helps you understand what you could do to optimize it to your situation!

Comment
RSunity
JesusChristChangedMe
superventure

People who like this

3 Show 7 · 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 Jesus_Freak · Dec 08, 2010 at 01:32 AM 0
Share

right now, the default string to be "GUI'd" is empty, so it won't play until you change it like shown in the second code.

avatar image RSunity · Dec 08, 2010 at 01:34 AM 0
Share

Thank you, helped a lot.

avatar image Jesus_Freak · Dec 08, 2010 at 01:40 AM 0
Share

sure! glad to help! if you need help with anything or something isn't just right, let me know, with specifics, and i or anyone else could possibly help you more.

avatar image Jesus_Freak · Dec 08, 2010 at 01:47 AM 0
Share

i'll check into it. until then, you could change the first static var to make it look like:

static var Str : String = "My Message"; and change the "My Message" to whatever you want. for right now...

avatar image Jesus_Freak · Dec 08, 2010 at 01:50 AM 0
Share

well, i see you deleted your comment, so i guess you figured it out. but i tested it myself just to be sure, and it works for default, now i'll check if you can edit the words.

Show more comments
avatar image

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

For anyone looking for something similar, i made a simple message box, easy to use, feel free to try it: Simple-Message-Box-Unity on Github

Comment

People who like this

0 Show 0 · 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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

2 People are following this question.

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

Can someone help me with this script please 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