- Home /
unity 4.6 UI disabling click/touch detection on objects behind user interface
Specifically I have a scene with some objects that are clickable! They have a collider on them and a script which detectes OnClick() and reacts! Now when I click one of them a pop up appears with some buttons! When I click a button of the UI menu if there is an object behind that button it also clicks this! Is there a way to no detect click action behind a specific button or img?
Answer by Kiwasi · Dec 13, 2014 at 02:52 AM
There are a couple of ways to do this. The best is to kill OnClick and replace it with the IClickHandler interface from the UnityEngine.EventSystems namespace. You will also have to add a physics raycaster to the camera.
The alternative is to check EventSystem.IsPointerOverGameObject
Edit: Adding a YouTube video, since the question has been asked a few times
Thanks for the answer! I tried EventSystem.IsPointerOverGameObject and it works ok with the mouse click, but not with touch! I'm more interested in touch than mouse click! The other way you told me to try, I could not test. I don't know how to... If you got an example to give me it would be nice!
Thanks again!
Thanks! IsPointerOverGameObject was just what I was looking for.
Your answer
Follow this Question
Related Questions
Make UI element only appear if object is present (unity 4.6) 1 Answer
Object detection in front of Character 1 Answer
How to detect if there is a floor in front of a character? 2 Answers
How to use On-Screen Buttons in unity 5 {URGENT} 1 Answer
GUI On button click change visibility of array objects 0 Answers