【问题标题】:Scripted GUI button doesn't appear on Android脚本化的 GUI 按钮不会出现在 Android 上
【发布时间】:2015-09-25 14:49:00
【问题描述】:

我正在使用 Unity 开发一个跨平台的应用程序。

我正在使用以下 C# 代码在屏幕上放置一个按钮:

void onGUI()
    {
        float texWidth = m_buttonPano.normal.background.width;
        float texHeight = m_buttonPano.normal.background.height;

        float width = texWidth * Screen.width / 1920;

        float height = (width / texWidth) * texHeight;
        float y = Screen.height - height;
        float x = Screen.width - width;
        if (GUI.Button (new Rect (x, y, width, height), "", m_buttonPano)) {
            if (this.TappedOnPanoButton != null) {
                this.TappedOnPanoButton ();
            }
            m_guiInput = true;
        }
    }

另外请注意,我通过创建一个空的 GameObject 并将脚本附加到它来将此脚本添加到我的场景中。

它在 PC 上运行良好,但在 Android 上该按钮不显示。有趣的是,如果我点击它的位置(右下角),功能会被保留,因此只有我放在它上面的自定义背景纹理不会显示出来。..

另外,这里是背景纹理的附件代码:

m_buttonPano = new GUIStyle();
m_buttonPano.normal.background = Resources.Load("GUI/buttonPano") as Texture2D;
m_buttonPano.active.background = Resources.Load("GUI/buttonPano") as Texture2D;
m_buttonPano.onActive.background = Resources.Load("GUI/buttonPano") as Texture2D;

【问题讨论】:

    标签: c# android user-interface unity3d


    【解决方案1】:

    问题实际上是一个 Unity 错误。下载f4补丁后,一切正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-12
      • 2020-04-17
      • 1970-01-01
      • 2011-11-30
      • 2014-06-12
      • 1970-01-01
      • 2014-02-27
      • 1970-01-01
      相关资源
      最近更新 更多