- Home /
OnTriggerEnter GUI
I have been trying to use the function OnTriggerEnter(other : Collider) { }
to make it so when you run into the box collider a text GUI will pop up, than after a few seconds go away, I have tried but failed, I need help please
Answer by Sriram · Feb 24, 2011 at 05:11 AM
If you want the GUI to appear when you hit the collider you could just have a boolean (say bShowGUI) and set it to false initially.And in you OnTriggerEnter function you could set that to true.Your OnGUI function will now render the GUI only when the bool returns true.
Eg:(This is rough untested code in C#)
private bool bShowGUI = false;
void OnTriggerEnter(Collider collider) { bShowGUI = true; }
void OnGUI() { if(bShowGUI) //DrawButton/Label etc
}
Hope this helps
Your answer
![](https://koobas.hobune.stream/wayback/20220613105956im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Unity freezes when changing GUI.Color.a 1 Answer
Limit on GUI Components? 0 Answers
For Loop GUILayout.Label Problems 1 Answer
How To Make Ammo & Realod for Gun & Spark for Gun ? 0 Answers