x


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;

}

more ▼

asked Dec 23 '11 at 02:23 AM

cariaga gravatar image

cariaga
37 5 6 8

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Dec 23 '11 at 02:29 AM

Lo0NuhtiK gravatar image

Lo0NuhtiK
3.5k 1 9 39

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...

Dec 23 '11 at 05:05 AM cariaga

I don't get it... "the first person Enters the GUI" ?? The 3D character enters 2D space??

Dec 23 '11 at 05:16 AM Lo0NuhtiK

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

Dec 23 '11 at 12:47 PM cariaga
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3668
x2482
x980
x58

asked: Dec 23 '11 at 02:23 AM

Seen: 2104 times

Last Updated: Dec 23 '11 at 07:13 PM