【发布时间】: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