Unity GUILayout.TextField刷新

时间:2014-10-28 13:22:45

标签: user-interface unity3d textfield

我有一个GUILayout.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();
}

0 个答案:

没有答案