#How to detect mouse clicking world space (not UI) object with new Input System?

1 messages · Page 1 of 1 (latest)

normal echo
#

I've already tried using IPointerClickHandler interface with physics2Draycaster on the camera. Also, I've tried making a script to register clicks that calls an interface. (this is a 2D project)

lean pecan
#

I'm guessing the actual problem is that you're using Physics.Raycast instead of Physics2D.Raycast. The former works with only 3d colliders instead of 2d.

BUT from my understanding, even when you use Physics2D.Raycast things will still not work. That's because Physics2D.Raycast takes Vector2 as inputs (instead of Vector3), this api assumes that you'll only perform a 2d raycast on a single plane.

To achieve what you want ( I'm guessing you're trying to cast a 3D ray against 2D colliders), take a look at Physics2D.GetRayIntersection instead.

Here's the document of the API: https://docs.unity3d.com/ScriptReference/Physics2D.GetRayIntersection.html