Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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

2 Answers 2

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
        Event.current.Use();
    }
    GUI.depth++;
    // Do other stuff
    GUI.depth = prevDepth;
}
share|improve this answer

Your Answer

 
discard

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.