- Home /
Overlapping GUI Button priority
I'm making a game which has complex GUI windows and pop-ups, and a 3D world.
I have made a system to prevent the physics raycasts from occurring during mouse-clicks on the GUI, but that's not what my problem is.
My problem is that when a pop-up with an "ok" button appears, and that button happens to line up with a button on the window behind, it clicks the button on the behind window and not the pop-up window button in front.
Is there a way to tell Unity which of two overlapping buttons I want it to listen to first?
Answer by andrew-lukasik · Jun 18, 2014 at 09:18 AM
If they're drawn from separate scripts then try using GUI.depth
I use GUI.depth to ensure that the popups are on top. SHould I use gui.depth on the buttons and not just the frames? aah of course! YOu're a genius!
Answer by magicaxis · Jun 19, 2014 at 02:32 AM
I made my popup windows their own script. I made it so that each popup was the same exact instance that appeared and disappeared, so I could make it static. Then I changed every time I have a button in my program to check if the popup is there. If the popup is visible, nobody draws any buttons, so there can be no accidental clicking. Hacky but functional.
Answer by MonemAhmed · Jun 18, 2014 at 01:12 PM
you can put button in different layer and when you use raycast defina a ;ayer to which you want recieve touches
Raycast(origin: Vector3, direction: Vector3, hitInfo: RaycastHit, distance: float = Mathf.Infinity, layerMask: int = DefaultRaycastLayers): bool;
in this change "DefaultRaycastLayers" time by time it will recieve touches in only given layers.