I see lots of GUI related questions, but none that fit my curiosity.
I’m trying to do something in theory seems simple. I want to display dialog to the player.(For instance when the character has approached a sign, a dialog telling the player what the sign says)
The problem is, since GUI code runs similiar to Update(), I’m not quite sure how to implement it.
You can use a trigger attached to each object that should display a message, and enable this message when the player enters the trigger - something like this (attach to the trigger):
var message: String; // define the message at the Inspector
var dispMsg: boolean = false;
function OnTriggerEnter(col: Collider){ // enable message on enter
if (col.tag == "Player") dispMsg = true;
}
function OnTriggerExit(col: Collider){ // disable message on exit
if (col.tag == "Player") dispMsg = false;
}
function OnGUI(){ // only display message if enabled
if (dispMsg) GUI.Box(Rect(5, 5, Screen.width - 10, 45), message);
}