- Home /
gui text problem.
i have a tigger called trigger one which is just a box collider and when the player hits it i want it to display a welcome message. its not giving me errors but its also not showing up. any ideas? here is my code: var trigger1 = false;
function OnTriggerEnter (myTrigger : Collider) {
if(myTrigger.gameObject.name == "ball")
{
Debug.Log("it hit!");
trigger1 = true;
}
else
{
trigger1 = false;
}
} function Update() { if(trigger1 == true) { guiText.text = "welcome to marbleMadness";
}
} ... this is attached to my colider
Answer by adrenak · Jan 19, 2012 at 10:02 AM
Your method is not very good, you dont have to keep changing the text value of text to "welcome to marbleMadness" every frame by keeping it in the Update function.
Try this :
Make a GUIText by going to GameObject > Create Other > GUIText and position the GUI Text anywhere you want on the screen. In the inspector you can change the text and font it shows and other settings.
/ This script goes to the trigger that you want to show the welcome message /
var textBox : GUIText;
var trigger1 : boolean;
function Start(){
textBox.text = " "; //textBox is empty initially
}
//OnTriggerEnter is the same as yours
function OnTriggerEnter (myTrigger : Collider) {
if(myTrigger.gameObject.name == "ball"){
Debug.Log("it hit!");
trigger1 = true;
textBox.text = "Welcome to marbleMadness! "; //or any other text you might want
}
else{ //else isn't really required...
trigger1 = false;
}
}
I Hope this helps