Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a GUI.Box that I slide in from the side of the screen. How can I prevent mouse interaction from going to any objects under it (another GUI.Button for instance, or for that matter an GameObject)?

share|improve this question

This is one of the annoying limitations of the built-in version of Unity's GUI. From most accounts I've seen, you have to do it yourself. Write an input manager that checks locations of mouse clicks and then decides to forward or not the clicks to whatever game systems you want.

Alternatively, use a different kind of input system that is based off of colliders. A popular one is NGUI.

share|improve this answer
I checked out NGUI, unfortunately (at least the free trial) has very poor performance. If there an example input manager I could look at someplace? – Justin808 Jan 31 '13 at 6:36
@Justin808 By all accounts I've seen NGUI is significantly higher performing than the built in GUI. The built in one (last time I checked) uses one draw call per GUI element. And the entire OnGUI chain is ran multiple times per frame (once per input event). With NGUI you can at least get your entire UI down to a single draw call. – Tetrad Feb 1 '13 at 19:40
I've bought it to try it out. The unity player samples on the website were choppy on a 2nd gen MBA. I'm hoping that it was just a fluke. My 3nd gen MBA worked fine with them. – Justin808 Feb 1 '13 at 20:20

This could be done fairly simply and elegantly with GUI.depth and styling a GUI button as a box.

void OnGUI()
    int prevDepth = GUI.depth;
    GUI.depth = 0;
    if(GUI.Button(someRect, "Some Button","Box"))
        // Do something
    // Do other stuff
    GUI.depth = prevDepth;
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.