- Home /
Help for raycasting 2d with multiple layers
Hello,
I have a background layer which takes all my camera background. In front of it I put some obstacles. I would like to add a pointer which only shows when the mouse is over the background part but not an obstacle. I send a Raycast2D only on the background layer, but since my background is also behind the obstacles, the raycast hits everywhere :(
So I thought of 2 solutions
Cast a RaycastAll and if the length is > 1, then I know there is an obstacle in front of the background
Rework the background to not make it go behind the obstacles.
Those two solutions don't seems to be the best. I'm sure there is something better but I don't see it.
Do you have an idea ?
Answer by Izina · Sep 12, 2016 at 10:14 PM
Found this solution which I find cleaner :)
((1<< hitInfo.transform.gameObject.layer) & layerMask) != 0
It works well, what do you think ?
Your answer
Follow this Question
Related Questions
BoxCast, OverlapArea, and Raycasting; ground detection questions 0 Answers
Object jumps through roof when holding "Up" button? 1 Answer
How to do a raycast to make my player unable to move through certain objects? 2 Answers
My Raycasts seem to sometimes miss 0 Answers
Raycast for 2d with touch. 0 Answers