detecting if the mouse is inside any gui element

Hey,

I’m working on an application that has RTS like elements. The user selects objects with the left mouse button moves them to a new position with the right mouse button.

Left clicking on an non selectable object (the ground for instance) will deselect the currently selected object. When an object is selected, various GUI elements (texts, boxes, buttons etc.) sometimes within a window, sometimes not, will appear in the middle of the screen.

At the moment when the user clicks a button on the GUI, it counts as a left click for selection and selects an undesired object or deslecets the current one.

What I would like to know is if there is a universal way of detecting if the mouse has been clicked while it is is over a GUI element.

I understand that some GUI elements have colliders and some don’t. I can also imagine that it would be possible to do a on mouse enter type function for every single available type of GUI element but this seems like an inefficient method.

Is there a tag I can check for or a function I can call to tell if the mouse is over a GUI element? This way, when it is I can disable the ability to select/deselect my objects with the mouse.

One dirty way to deal with this is to make an invisible button the size of the screen and use depth to make sure it is behind all your other buttons. If that button gets clicked on, you know that the player has not clicked on any other buttons.