Unity 5- GUI 文本字段在 Android Build 上无法正常工作(出于某种原因,皮肤无法正常工作,我无法更改文本)

Unity 5- GUI Textfield doesn't work properly on Android Build (The skin for some reason doesnt work and I cant change the text)

所以,我有一个 GUI 文本字段供用户输入他或她的名字,这在编辑器上工作正常但在 Android Build 上不工作。

文本可以在编辑器中完美更改:

但与在编辑器中不同的是,当我构建 APK 并在我的 android 设备中启动我的应用程序时,一切都是这样发生的:

1- 我点击文本框,Android 键盘自动弹出。
2- 我写了名字,文本字段确实改变了
3- 我在 Android 键盘
上点击完成 4- 文本变回 "Name" 这意味着字符串没有被存储?

哦,我在 GUI 皮肤上设置的字体在 Android build 上都不起作用。

代码比较简单:

   void OnGUI(){
    GUI.skin = StandardStyle;
    if (AllowGUI) {
        if (PlayerPrefs.GetInt ("Language") == 0) {
            Name = GUI.TextField (new Rect (Screen.width / 6.69230f, Screen.height / 2.26818f, 340, 50), Name, 15);
            CompanyName = GUI.TextField (new Rect (Screen.width / 6.69230f, Screen.height / 1.71f, 340, 50), CompanyName, 25);
        }else if(PlayerPrefs.GetInt ("Language") == 1){
            Name = GUI.TextField (new Rect (Screen.width / 6.69230f, Screen.height / 2.0818f, 340, 50), Name, 15);
            CompanyName = GUI.TextField (new Rect (Screen.width / 6.69230f, Screen.height / 1.61f, 340, 50), CompanyName, 25);
        }
    }
}

您正在使用 IMGUI,它旨在用作编辑器工具。 当您使用任何需要 OnGUI 功能的东西时,您应该停下来寻找替代解决方案。

要获取用户的输入,请使用 InputField that comes with the new Unity UI (uGUI). The #3 on post explains how to detect submit on an InputField

要创建一个 InputField,转到 GameObject-->UI-->输入字段.

您可以了解有关新功能的更多信息 UI here