- Home /
activate gui on trigger enter
what im trying to do i activating a gui if the person enters a trigger then reset to hide if exiting a trigger
var showGUI = false;
var source2 : Texture2D;
var source : Texture2D;
function OnTriggerEnter(other : Collider){
if(other.gameObject.tag == "source"){
GUI.Box (Rect (10,10,200,100), GUIContent("400", source));
showGUI = true;
GUI.enabled = true;
}
}
function OnTriggerExit(other : Collider){
if(other.gameObject.tag == "source2"){
GUI.Box (Rect (10,10,200,100), GUIContent("400", source2));
showGUI = false;
GUI.enabled = true;
}
}
function ongui () {
GUI.Box (Rect (10,10,200,100), GUIContent("400"));
GUI.enabled = true;
}
Answer by Lo0NuhtiK · Dec 23, 2011 at 02:29 AM
EDITED
Ok, I changed this for what you said below, I think this should work. Just attach this script to your player ... You'll have to modify it for whatever other content you're wanting to do, I'm just showing you a way I think for you can trigger the gui.
var showGUI : boolean = false ;
function OnTriggerEnter(hit : Collider){
if(hit.gameObject.tag == "MyGuiDoohickeyTagWhateverInamedIt"){
showGUI = true ;
}
}
function OnTriggerExit(hit : Collider){
if(hit.gameObject.tag == "MyGuiDoohickeyTagWhateverInamedIt"){
showGUI = false ;
}
}
function OnGUI(){
if(showGUI){
//do what you're doing with gui.. making your box or whatever
}
}
I think that should do it. Just tag your GUI trigger object whatever you want and replace the "MyGuiDoohickeyTagWhateverInamedIt" in the script to whatever your tag is called. Then add some script for GUI.Box or whatever down near the bottom there.
im trying to activate it on a trigger so if the first person enters the gui it will display the specific gui. if its out side the trigger it will be invisible what im trying to do is like a navigator...
I don't get it... "the first person Enters the GUI" ?? The 3D character enters 2D space??
what i mean is. first person "enters trigger" and it will activate the gui that has specific texture2d and if it exits the trigger it will make the gui invisible sorry :P bad English
Your answer
Follow this Question
Related Questions
Trigger GUI working wrong 1 Answer
gameObject.enabled is not working 1 Answer
Collision between objects? 2 Answers
OnTriggerEnter not working all the time. 2 Answers
GUI text like GTA 2 Answers