- Home /
calling buttons in triggers
its annoying me that unity wont let me call a GUI Button function in an OnTriggerEnter function after the if statement. I want to make instructions come up when you enter a trigger, but unity tells me that the I can only call GUI functions from inside OnGUI(). any ideas around this?
heres the script so far:
var tips1 : GUIText;
var tipsPREFAB : GUIText;
function OnTriggerEnter (player : Collider)
{
if(player.gameObject.name == "BlueMan")
{
OnGUI();
}
}
function OnGUI ()
{
(GUI.Button (Rect(10, 300, 100, 80), "press T for help "));
}
When posting code, make sure it's formatted or people will likely ignore your question. You can see how it's going to look with the preview box as you're writing your question.
Answer by Chris D · Jul 18, 2011 at 08:45 PM
You'll find lots of info for your problem by searching for "pause menu" and the like in the search box. This one here seems to be a pretty decent solution; just substitute an OnCollisionEnter
for the if (Input....)
position in Update.
Essentially, whatever you put in OnGUI is going to get called every frame. To get the behaviour you want, you have to enable and disable the buttons/text according to an outside condition.
Your answer
![](https://koobas.hobune.stream/wayback/20220612150216im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Creating re-usable action triggers 1 Answer
IsTouching and IsTouchingLayers for Colliders are not defined? 1 Answer
How do I call a function containing a while loop, inside the update function? 2 Answers
Getting only one collider form OnTriggerEnter2D or OnCollisionEnter2D. 0 Answers
Get Object, Trigger Attached Method,Trigger method on collider script 1 Answer