- Home /
How to make sure mouse events go to the UI layer
This is a 2D puzzle game in 2 main layers. The game is in the 'default' layer at Z=0, camera Z=-10. The UI is in the 'UI' layer and the top canvas is in render mode Screen Space Camera, plane distance 100. Most of these values are more or less defaults, and it all works fine, except for the mouse.
If both game and UI are drawn then the UI visually overlays the game, as desired, and visually the mouse events should go to the UI. Unfortunately in 3D space the game is closer to the camera and mouse events go to the game, not to the UI. This seems to be the documented working of the canvas raycaster, but it isn't what I need.
The question is how to direct mouse events to the UI and prevent any mouse events reaching the game while the UI is visible.
Answer by Oliver-Bogdan · May 17, 2017 at 03:24 PM
On the Canvas there is a component called Graphic Raycaster
Make sure that Blocking Objects for this component is set to "None" and it should ignore any 3D elements.
https://docs.unity3d.com/Manual/Raycasters.html
https://docs.unity3d.com/Manual/script-GraphicRaycaster.html
Your answer
Follow this Question
Related Questions
Coroutine Chain of Events 1 Answer
Click on GameObject leads to multiple call 1 Answer
how can i instantiate a GameObject in mouse position and in a special distance from the camera? 2 Answers
Checking the position of the mouse cursor in 3d space 2 Answers
Unity UI/Events - how to do something for as long as UI button is pressed 2 Answers