I\'m writing a 3D maze program in C# and I need to have UI Text display \"You Win!\" When the player reaches the end of the maze.
I have a trigger set up in Unity as a c
First of all, it is OnGUI
not OnGui
. The spelling counts. If you find yourself using OnGUI
, stop and find other ways to accomplish whatever you are doing.
GUIText
is a legacy UI Component. It's old and the Text
component should now be used. If you still want to use it, below is the proper way to use GUIText
.
public GUIText winText;
private bool FinishLine = false;
void Start()
{
FinishLine = false;
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Player")
{
FinishLine = true;
winText.text = "You Win";
}
}
Text
component should be used for this and below is how to do that with the Text
component:
public Text winText;
private bool FinishLine = false;
void Start()
{
FinishLine = false;
}
void OnTriggerEnter(Collider col)
{
if (col.tag == "Player")
{
FinishLine = true;
winText.text = "You Win";
}
}
You can learn more about Unity's new UI here.