- Home /
Question by
robounited · Feb 25, 2013 at 10:05 AM ·
javascripttriggers
How do I condense my code for my triggers?
Hi Everyone, I'm here again :)
I have a trigger outside each door so when I collide with it it shows the room number and says press C to open the only problem is I have a different script for each door so it shows I different room number.
My code is below, I just what to know how I would compress it down to a single script if possible.
var displayMessage = false;
var font : Font;
var fontSize : int = 20;
function OnTriggerEnter (other : Collider) {
displayMessage = true;
}
function OnGUI () {
if (displayMessage){
GUI.Label (Rect (10, 10, 200, 60), "Room 2\nPress C To Open");
GUI.skin.label.font = GUI.skin.button.font = GUI.skin.box.font = font;
GUI.skin.label.fontSize = GUI.skin.box.fontSize = GUI.skin.button.fontSize = fontSize;
}
}
function OnTriggerExit (other : Collider) {
displayMessage = false;
}
Comment
Answer by Graham-Dunnett · Feb 25, 2013 at 10:51 AM
Use a variable that stores the room number, and set that from the inspector.
how would i do that then, im new to scripting haha would it be something like a string saying if trigger 1 collision, display message GUI.Label (Rect (10, 10, 200, 60), "Room 2\nPress C To Open"); or something :S
Your answer