2015-06-23 41 views
1

在我的遊戲中,我想要一個單擊按鈕時覆蓋一個字符串的按鈕。這個字符串然後會顯示在上面的一些文本中。到目前爲止,它會非常錯誤的...在Unity中使用gui顯示變量

這裏是代碼(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() { 

} 
} 

任何想法?

回答

1

你在下面的行犯了一個錯誤:

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

應該

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

更改逗號,爲加+;

+0

Thankyou SOOOOO多! – DubGamer87