- Home /
Making a text box appear after a certain gameObject is destroyed
I am trying to make a GUI.Label text box that reads "Game Over" pop up if the enemy the script is attached to collides with the player. Everything in the first if statement works great except for the GUI.Label. I've also tried using a boolean value if the player was destroyed to give it a false value, but that didn't seem to work either. I'm pretty new to coding and would like to know if I'm missing something obvious here or if there is a better way to go about doing this. Thanks in advance!
public GameObject enemy;
public GameObject player;
public Transform enemySpawn;
void OnTriggerEnter2D(Collider2D coll)
{
Vector2 position = new Vector2(11.09f, Random.Range(-2.2f, 4f));
if (coll.gameObject.tag == "Player")
{
Destroy(coll.gameObject);
void OnGUI ()
{
GUI.Label(new Rect(340, 180, 200, 50), "GAME OVER");
}
}
if (coll.gameObject.name == "Enemy Instantiate Trigger")
{
Instantiate(enemy, position, enemySpawn.rotation);
}
}
Comment
Your answer
Follow this Question
Related Questions
OnGUI called after LateUpdate screwing up debug text database 1 Answer
Can't draw GUI.Label text on subpixel values 0 Answers
GUI activate and destroy 1 Answer
Fade out GUILayout Area? 1 Answer
Destroying GUI.Label after X seconds 2 Answers