Urgent: Detecting GUI's with a mouse

I’m trying to detect whether the mouse is over a GUI or not. Using GUILayer.hitTest() returns null everytime. Is there any way to do this?

Are you using GUIElements, or OnGUI? GUILayer is for GUIElements only.

–Eric

Testing it against OnGUI elements though isn’t harder. As you likely store all rects of the elements somewhere you can just use the Rect.Contains functionality to do tests.

I’m using OnGUI for GUIs. How should I go about detecting the GUIs with the mouse?

You’ll need to code the support yourself for that. What I did was create a Widget class that draws things on the screen using the GUI library. The Widget class keeps the position/size Rect and on a mouse-click event checks to see if it’s within any Widget rects currently visible on the screen.

It may seem like a bit of work but it’s pretty quick and once you have it set up you can extend it quite easily like doing sorting, exclusive widgets (ie, when Widget A is up no other Widgets or anything else should be receiving input), etc.

Yup. So just be sure to change new_y = Screen.height - old_y