Displaying variables using gui in Unity

那年仲夏 提交于 2019-12-13 02:15:22

问题


In my game, I want a button that when clicked on, overwrites a string. This string will then be displayed in some text above. So far it is going very wrong...

Here is the code ( in C#) that I use:

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 () {

}
}

Any ideas?


回答1:


You've made a mistake in following line:

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

should be

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

Change the comma , to a plus +;



来源:https://stackoverflow.com/questions/31007997/displaying-variables-using-gui-in-unity

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