5
\$\begingroup\$

How do I consume the input events in the new 4.6 unity gui system? If I click on a button for instance I don't want anything else non GUI related that might be listening for mouse input to react to the event.

\$\endgroup\$
4
\$\begingroup\$

Here's a solution from the Frequently Asked UI Questions thread on Unity Forums:

How do I stop clicks/touches on the UI from 'going through it' and being clicks in my game world?

Use EventSystem.current.IsPointerOverGameObject() to check whether the mouse is over a GUI element before you process your game world clicks. See this post for an example. Also, on mobile, you may need to specify which finger you're asking about - see this thread for details.

I should warn though that while this method seems working (I'm using it myself), it is still not documented at the moment, and there is no guarantee it won't be changed in future when Unity 4.6 is officially released.

| improve this answer | |
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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