本文介绍了在Unity中使用gui显示变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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...

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

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

}
}

有什么想法吗?

推荐答案

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

You've made a mistake in following line:

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

应该是

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

将逗号,更改为加号+;

这篇关于在Unity中使用gui显示变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 22:31