- Home /
Raycast Target does not block mouse click
I have a 2D game with the play field on the default canvas (z = 0.5). The UI buttons are on another canvas on z = 0.0. I want to prevent mouse clicks from going through to the UI buttons after the player has won the game, so I cover the entire screen with a UI Text (enabled when the player has won the game)
I tried
1) Adding a UI Text on the default canvas. 2) Adding a UI Text on the UI buttons canvas. 3) Adding another canvas (z = -0.5) and make the UI Text a child object to this canvas.
For all 3 options, the Raycast Target option is checked. However, the UI buttons are still clickable.
Appreciate any advice on this issue.
Thank you!
Answer by Athomield3D · Dec 21, 2017 at 12:15 PM
Use this assertion in the same if statement as the raycast: !EventSystem.current.IsPointerOverGameObject(-1) PS: change -1 to 0 for mobile
Your answer
Follow this Question
Related Questions
UI element in 3D space, reacts to click despite raycast target being infront 0 Answers
How to prevent raycast when clicking 4.6 UI? 1 Answer
Drag object and position(snap) on another similar one using Raycasting? 0 Answers
What's an easy way to align a UI element with a Raycast? 0 Answers
Create UI raycast like a mouse Click 2 Answers