[英]Scripted GUI button doesn't appear on Android
我正在使用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;
问题实际上是Unity错误。 下载f4补丁后,一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.