Button 鼠标点击不会注册
这是我的GUI功能,如您所见,我有三个按钮。“退出”和“返回”按钮工作正常,但当我单击“信息”按钮时,将不会注册任何内容 我把GUI.Button rect450200,Screen.width/2,Screen.height/2,info;这行代码在if语句之外,用来检查它是否工作,它是否会工作,但是当它在语句内部时,我什么也得不到 谁能告诉我为什么Button 鼠标点击不会注册,button,user-interface,unity3d,Button,User Interface,Unity3d,这是我的GUI功能,如您所见,我有三个按钮。“退出”和“返回”按钮工作正常,但当我单击“信息”按钮时,将不会注册任何内容 我把GUI.Button rect450200,Screen.width/2,Screen.height/2,info;这行代码在if语句之外,用来检查它是否工作,它是否会工作,但是当它在语句内部时,我什么也得不到 谁能告诉我为什么 var note : String = "blah" function OnGUI() { if (IsPaused)
var note : String = "blah"
function OnGUI()
{
if (IsPaused)
{
GUI.Box (Rect (580,20,100,210), "Pause");
if (GUI.Button (Rect (590,130,80,20), "Info"))
{
Debug.Log("I pressed it");
GUI.Button (Rect (450, 200, Screen.width/2, Screen.height/2), info);
}
else if (GUI.Button (Rect (590,160,80,20), "Quit"))
{
Application.Quit();
}
else if(GUI.Button (Rect(590,190,80,35), "Back"))
{
IsPaused = false;
GetComponent(LookAtMouse).enabled = true;
}
}
@rutter感谢您的想法,我使用了您的布尔思想并创建了一个切换来检查,如果信息显示,则在切换时创建文本字段的实例记住GUI是在即时模式下绘制的:如果您希望在每一帧中都显示一个按钮,则需要在每一帧中绘制它。同时,当按下GUI.Button时,只有一次返回true。您可能会更幸运地缓存一些布尔标志来控制某些UI元素的显示。请不要在问题中使用攻击性语言。
var displayInfo : boolean = false;
if (IsPaused)
{
GUI.Box (Rect (580,20,100,210), "Pause");
displayInfo = GUI.Toggle(Rect (590,130,80,20), displayInfo, "Info");
{
if(displayInfo)
{
GUI.Button (Rect (450, 200, Screen.width/2, Screen.height/2), info);
}
}