【问题标题】:Displaying variables using gui in Unity在 Unity 中使用 gui 显示变量
【发布时间】:2015-09-09 13:26:33
【问题描述】:

在我的游戏中,我想要一个按钮,单击该按钮会覆盖字符串。然后,该字符串将显示在上面的某些文本中。到目前为止,它变得非常错误......

这是我使用的代码(在 C# 中):

using UnityEngine;
using System.Collections;

public class ConnectGUI : MonoBehaviour {
private string map = "No map selected.";

// Use this for initialization
void Start () {

}
void OnGUI () {
    GUI.Label(new Rect(10,10,200,90), "Map selected: ", map);
    if(GUI.Button (new Rect(10,50,90,20), "Pier")){
        map = "Pier";
        }
    }

// Update is called once per frame
void Update () {

}
}

有什么想法吗?

【问题讨论】:

    标签: c# user-interface unity3d unityscript


    【解决方案1】:

    您在以下行中犯了一个错误:

    GUI.Label(new Rect(10,10,200,90), "Map selected: ", map);
    

    应该是

    GUI.Label(new Rect(10,10,200,90), "Map selected: " + map);
    

    把逗号,改成加号+

    【讨论】:

    • 非常感谢你!
    猜你喜欢
    • 1970-01-01
    • 2010-11-12
    • 2021-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-15
    • 1970-01-01
    • 2016-10-30
    相关资源
    最近更新 更多