Hello,
I just spent the last 2 hours to try to figure out a clean way to detect a click on “nothing” (ie: no 3D colliding objects nor script created GUI Buttons under the mouse cursor during the click), so I could deselect my current selected object.
For the 3D colliding objects, I had to use a global variable updated by OnMouseEnter/OnMouseExit (which is easy clean enough), and for the GUI Buttons, I had to use the Tooltip.
But there are 2 problems with the ToolTip :
- as far as I can tell, GUI.tooltip is only valid in the current OnGui() ; ie: if it’s set in a OnGui() of a GUI object, it will be still empty in all other GUI objects’ OnGui() ; so I had to create my own global Tooltip which must be set manually from each OnGui()
- Tooltip is turned off when the mouse button is clicked, so I had to add 1 extra function call for this case
All in all, it’s a hell lot of stuff to just catch a mouse click that lands on nothing… And now, I still have to manually add at least 2 function calls in all my GUI objects’ OnGui() + the Tooltip for all Gui parts.
And I also have to pray that my code is bug proof with all the possible cases of interaction of Unity GUI with all of this… ![]()
I’d really wish it would have a simpler, faster safer way to do this. :roll: