- Home /
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.
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!
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.
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.
i'll check into it. until then, you could change the first static var to make it look like:
static var Str : String = "$$anonymous$$y $$anonymous$$essage"; and change the "$$anonymous$$y $$anonymous$$essage" to whatever you want. for right now...
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.
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