Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/user-interface/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
User interface Unity GUILayout.TextField刷新_User Interface_Unity3d_Textfield - Fatal编程技术网

User interface Unity GUILayout.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)

我有一个GUILayout.Textfield,我用它输入一个新的玩家名。但是,textfield中的文本永远不会刷新,尽管该值会根据控制台日志的不同而变化。知道如何刷新文本字段吗

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。