Efficent method to detect mouse events anywhere on screen.

I'm working on a type of interactive product viewer, where the user can click (almost) anywhere on screen and use the mouse to 'orbit' the subject model. Thats simple enough in an update function, but I also have several gui elements on screen and if one of these is clicked/drag I don't want the mouse orbit to trigger.

I have several ideas, but not sure which would be best or if anyone has any better solution.

My ideal solution would be to use a fullscreen guiTexture set to completely transparent. That way I can use OnMouseDown/OnMouseUp and OnMouseDrag to capture the interaction but other gui elements that are on top of it will intercept the mouse first. In this way the gui elements would capture events and not the fulscreen guiTexture.

However i'm unsure if setting the colour.alpha of a guiTexture to zero would mean Unity is clever enough to not bother rendering it, or whether it would regardless and let the gpu cull it at some point. Since this will be on a 1920x1080 monitor with an expensive to render model I don't want to adversely affect the performance.

Alternatively I could do it via scripting, flagging up if a gui element has been clicked and disable mouse orbit behaviour, but this isn't as clean and would require several levels of checks to make it work properly.

Perhaps some combination of checking what the mouse is over at the time of the click might help, but again its not as nice as the first proposal.

I've wondered about adding a collider without a mesh renderer and parenting it to the camera, that might work, though for some reason I don't like it ;)

Perhaps there is an easier way in Unity to achieve this though? Any thoughts?


With GUITextures, Unity just checks the Rect, it doesn't care about alpha values. In fact it doesn't even care if you're actually using a texture or not. If you have a full-screen GUITexture (scale (1,1,1), no pixel inset values), and a null texture, it will still respond to OnMouse events.