C# 在Unity中使用gui显示变量

C# 在Unity中使用gui显示变量,c#,user-interface,unity3d,unityscript,C#,User Interface,Unity3d,Unityscript,在我的游戏中,我想要一个按钮,当点击时,它会覆盖一个字符串。然后,该字符串将显示在上面的一些文本中。到目前为止,这是非常错误的 下面是我使用的代码(C#): using UnityEngine; using System.Collections; public class ConnectGUI : MonoBehaviour { private string map = "No map selected."; // Use this for initialization void Start

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

下面是我使用的代码(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 () {

}
}

有什么想法吗?

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

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

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

将逗号
更改为加号
+

非常感谢你!