DubGamer87
DubGamer87

Reputation: 143

Displaying variables using gui in Unity

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?

Upvotes: 1

Views: 2056

Answers (1)

d4Rk
d4Rk

Reputation: 6693

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 +;

Upvotes: 1

Related Questions