简体   繁体   中英

Scripted GUI button doesn't appear on Android

I'm using Unity to develop a cross-platform application.

I'm using the following C# code to place a button on screen:

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.

It works well on PC, but on Android the button doesn't show up. 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. After downloading the f4 patch, everything works correctly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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