x


Help With Message System Script

After not being able to find a way to display messages in a text box (for things such as characters talking and messages displaying on screen), I decided to write my own script to do this. The code I have at the moment is below:

var MessageBoxSkin : GUISkin;
var MessageBoxText : String;
var showText : boolean = false;


function DisplayMessage(message : String) {
        print(message);
        showText = true;
        MessageBoxText= message; 
}


function OnGUI()
{
    if (showText)
    {
    GUI.BeginGroup (new Rect (Screen.width / 2 - 640, Screen.height / 2 - 360, 1280, 720));

    GUI.skin = MessageBoxSkin;

    GUI.Box (new Rect (40, 600, 1200, 100),
    MessageBoxText);

    GUI.EndGroup ();
    }
    else
    {

    }
}

function Update(){

if (Input.GetKeyDown(KeyCode.F) && showText)
    showText = false;
}

function Active(){
return showText;
}

I have the MessageSystem attached to an empty gameobject in the scene, and I get other scripts to call the MessagesSystem via Get Component.

I can get the MessageSystem to receive the message (in the DisplayMessage function) but Update and OnGUI never seem to get called, and thus the GUI Box never appears.

Any help?

more ▼

asked Jul 22 '10 at 10:55 AM

Deikkan gravatar image

Deikkan
198 8 9 19

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

My best guess is that you have the script disabled (which would let you call the functions from other scripts, but OnGUI and Update wouldn't fire).

The script itself looks ok

more ▼

answered Jul 22 '10 at 11:51 AM

Mike 3 gravatar image

Mike 3
30.5k 10 65 253

Thanks, I somehow got it working again. Can't remember what I changed though.

Jul 23 '10 at 08:09 AM Deikkan
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3695
x205
x161
x83

asked: Jul 22 '10 at 10:55 AM

Seen: 1357 times

Last Updated: Jul 22 '10 at 11:01 AM