- Home /
How do I create a GUI on collision detection?
My goal is to have a GUI appear when a collision is detected. I've got the collision detection part done, but the GUI doesn't appear. I've gotten GUIs to appear before, so I don't know exactly what I'm doing wrong. I guess part of my problem has to do with the way I have one function do something when another function returns true. I probably did that wrong, most of my coding experience is in Lua. And this isn't Lua, so I'm probably doing something wrong there. Can someone help or explain a better way to have a GUI appear when a collision is detected?
function OnTriggerEnter (other : Collider) { return (true); }
function OnGUI () { if OnTriggerEnter = true { if (GUI.Button (Rect (10,10,150,100), "I am a button")) { print ("You clicked the button!"); } } }
I'm not sure what your problem is.. But have you specified the Trigger checkbox for the GameObject's collider in the inspector?
Answer by Dracorat · Apr 17, 2013 at 09:08 PM
You kind of have the right idea - you just need to track this with a boolean.
var buttonReady : boolean = false; // I don't program in UnityScript so excuse any syntax error.
function OnTriggerEnter (other : Collider) {
buttonReady = true;
}
function OnGUI () {
if (buttonReady) {
if (GUI.Button (Rect (10,10,150,100), "I am a button")) {
print ("You clicked the button!");
}
}
}
Thanks, that worked fine. It's sort of an end of level type of thing, so I'll be having another script that will handle resetting everything to the way it was.
Your answer
Follow this Question
Related Questions
script to create gui when detection collision between cube and first controler person ?? 1 Answer
function GUI.DrawTexture with OnMouseEnter/Exit to change texture all within script? 0 Answers
GUI.Window function with variables? 3 Answers
Using a screen-drawn line to check for a collision [Vectrosity] 5 Answers