I’m casting a ray from a screen point like this:
Vector3 rayPoint = Input.mousePosition;
var ray = Camera.main.ScreenPointToRay(rayPoint);
Debug.DrawRay(ray.origin, ray.direction * 10, Color.yellow);
if(Physics.Raycast(ray, out hit))
Debug.Log(hit.collider.gameObject.name);
If you look at my screenshot that I have attached, you can clearly see that my yellow line is hitting the black object first, then going through to the “rock” behind it. However, my debug.log call is outputting “LeftRock” instead of the “CaveDoor”.
I have no idea why. You can clearly see the ray hitting the “CaveDoor” first.