Unity GUIText on Collision c#

断了今生、忘了曾经 提交于 2019-12-01 23:23:18

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!