When I click in the box, and mouse in the button’s area, Unity will call the doSomething() function. My question is: how to forbid the button’s event when some GUI controls in front of this button?
Have a second boolean, isCovered, when other GUI elements are in front of it. Whatever puts those GUI elements there can flip this boolean, and so your check would be:
thanks a lot!
But Can’t Unity forbid the button event automatically when something covered on it?
For example: there is a drop down list above the button, the num of the list item is dynamic changed. when user click the drop down list, the button may be covered. How to stop the button event in this situation?
There seem to be a few problems like this with the GUI system. We’re investigating them, but they might be bugs, in which case they’ll be fixed in the next update of Unity.
In this case you can turn your GUI.Box into a GUI.Button and throw away the return value. The first button would catch the input and the second button would never get it.