- Home /
Ontrigger issue with GUI label
Hi, I am trying to get a GUI text label to display upon the OnTriggerEnter function event. However, It appears that when I start the game the text for this label is already being displayed instead of only appearing once the trigger collision has initiated. Below is the code I have used, as we can see I have used a boolean to try to trigger when I wish to have the GUI text label displayed.
// public Transform currentCheckpoint;
public bool TextLose = false;
void Update()
{
if (TextLose == true)
{
OnGUI();
}
}
void OnTriggerEnter2D(Collider2D target)
{
if (target.tag == "Laser")
{
TextLose = true;
}
}
void OnGUI()
{
GUI.Label(new Rect(10, 10, 100, 20), "You lose!");
}
}
Any suggestions on how I can get the text to only display when the collision happens?
Your answer
![](https://koobas.hobune.stream/wayback/20220612112359im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with 2d Civ style map 0 Answers
Im getting an error ..Cannot implicitly convert type `UnityEngine.GameObject' to `BulletContrl' 3 Answers
How do I get the sprite pointing the right direction? 1 Answer
Android Native Screenshot function creats black Image 1 Answer
Find GameObject with value within script 2 Answers