- Home /
How do you display a text box on the GUI after a trigger
So I'm just beginning and I'm writing a simple script so that when the player collides with an enemy it gets destroyed and i want to display a 'You Lost!'/Game over text. The collision happens, player gets destroyed but text doesnt show, why? or else teach me a better way of doing the same thing. Also showText is defined as a private boolean variable.
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "enemy")
{
Destroy(gameObject);
bool showText = true;
}
}
void OnGUI(bool showText)
{
if (showText == true)
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), "You Lost");
}
Answer by Ali-hatem · Apr 08, 2016 at 10:39 AM
use the new UI system : using UnityEngine.UI;
:
public Text GameOver;
void Start(){
GameOver.gameObject.SetActive (false);
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "enemy")
{
Destroy(gameObject);
GameOver.gameObject.SetActive (true);
}
}
Your answer
Follow this Question
Related Questions
Problem with writing text in a box - typewriter style 1 Answer
Editing certain words in a single NGUI Text Box 0 Answers
How do I change the vertical space between lines in a GUI box? 0 Answers
Text and texture in GUI? 1 Answer
New GUI - Text not rendering in front of geometry if using a Mask 1 Answer