- Home /
The question is answered, right answer was accepted
Press button if you are inside a trigger (Sorry)
FIRST of all im sorry for all the things i've said recently i was just getting a little worked up because java is very frustrating since i have just got into it . thank you for the help i'm getting , any help will be appreciated.
SO my question is , how come this says ou can only call GUI functions from inside OnGUI?
var Switch : GameObject;
Switch = gameObject.FindWithTag("switch");
function OnTriggerEnter (other : Collider) {
if(other.tag == "Player"){
OnGUI ();
}
}
function OnGUI (){
if(GUI.Button(Rect(100,100,100,100),"Click to play")){
Switch.animation.Play("Bridge");
}
}
And also the Gui button appears even when im not inside the trigger . Feel free to edit my question if it will help me.
Answer by meat5000 · Oct 21, 2013 at 08:41 AM
if(other.tag == "Player")
{
OnGUI();
}
You have this function call to OnGUI() in a trigger. OnGUI() will get called several times per frame just from including the function.
Instead, enable/disable the element, perhaps by toggling a boolean declared with the rest of your variables.
Follow this Question
Related Questions
Trigger GUI working wrong 1 Answer
Restricting a key press to when youre in a trigger? 2 Answers
Can't click gameobject when over another trigger? 1 Answer
Handling mouse events in objects inside a trigger? 0 Answers
Is there a script that will trigger a gui texture when an object is destroyed? 2 Answers