Is there a way to make the buttons under another GUI element to not respond to click?
I have a toolbar of buttons on the bottom side of the game window and if I spawn another window over them those buttons are still clickable and the worst thing is if i have a button in the popup window over another button from the underneath GUI elements is not working.
This is yet another case of the GUI Click-through bug that plagues the standard GUI.Button. Haven’t we had quite a few of these recently? The bug is that buttons that are layered with other controls fail to honor a HotControl-indicator that is otherwise supposed to disable their response to mouse clicks. You can tell they’ve made an attempt to get this to work, because buttons with other controls on top of them do not, in fact, draw themselves in mouse-over style. This forum post discusses it, and also provides a solution:
As is mentioned therein, you don’t need to work out a solution with flags yourself, you just need a GUI.Button that works as intended. That post gives you one.
use the following code
private var CanTap : boolean;
function Start()
{
CanTap = true;
}
function OnGUI()
{
if(GUI.Button(Rect(10,70,50,30),"Click"))
{
if(CanTap)
{
Debug.Log("Clicked the button with text");
}
}
}
the moment you know there is a button above this button turn the variable CanTap false.