简体   繁体   English

脚本化的GUI按钮未出现在Android上

[英]Scripted GUI button doesn't appear on Android

I'm using Unity to develop a cross-platform application. 我正在使用Unity开发跨平台应用程序。

I'm using the following C# code to place a button on screen: 我正在使用以下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;
        }
    }

Also note, that I added this script to my scene via creating an empty GameObject and attaching the script to it. 还要注意,我通过创建一个空的GameObject并将脚本附加到场景中来将此脚本添加到场景中。

It works well on PC, but on Android the button doesn't show up. 它在PC上运行良好,但在Android上没有显示该按钮。 The interesting part is that if I tap at it's location (bottom right corner) the functionality is preserved, therefore it's only the custom background texture I put on it that doesn't show up.. 有趣的是,如果我点击它的位置(右下角),该功能将保留,因此只有我放在其上的自定义背景纹理不会显示。

ALso, here's the code of the attachment of the background texture: 另外,这是背景纹理的附件代码:

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;

The problem was actually a Unity bug. 问题实际上是Unity错误。 After downloading the f4 patch, everything works correctly. 下载f4补丁后,一切正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM