User interface Unity GUILayout.TextField刷新
我有一个GUILayout.Textfield,我用它输入一个新的玩家名。但是,textfield中的文本永远不会刷新,尽管该值会根据控制台日志的不同而变化。知道如何刷新文本字段吗User interface Unity GUILayout.TextField刷新,user-interface,unity3d,textfield,User Interface,Unity3d,Textfield,我有一个GUILayout.Textfield,我用它输入一个新的玩家名。但是,textfield中的文本永远不会刷新,尽管该值会根据控制台日志的不同而变化。知道如何刷新文本字段吗 private bool createProfile = false; private string playerName = "PlayerName"; void OnGUI() { //Display window to enter player name. if (createProfile)
private bool createProfile = false;
private string playerName = "PlayerName";
void OnGUI()
{
//Display window to enter player name.
if (createProfile)
{
Rect createProfileWindow = new Rect(Screen.width / 2 - 100, Screen.height / 2 - 35, 200, 70);
createProfileWindow = GUILayout.Window(2, createProfileWindow, CreateUserProfile, "New player");
}
}
void CreateUserProfile(int windowID)
{
//Pop up window to introduce player name. Add 'create' button.
GUILayout.BeginVertical();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
playerName = GUILayout.TextField(playerName, 50);
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();
if (GUILayout.Button("Create"))
{
PlayerPrefs.SetString("PlayerName", playerName);
PlayerPrefs.Save();
createProfile = false;
}
GUILayout.FlexibleSpace();
GUILayout.EndHorizontal();
GUILayout.EndVertical();
}
这个playerName=GUILayout.TextFieldplayerName,50;继续将值重新分配回自身?你能用一个中间变量吗?它不能,因为正确的值被存储了。所以,若我在那个里输入John,它将存储John,但它仍然会在屏幕上显示PlayerName。