#Raycast not working in a 2d world

1 messages · Page 1 of 1 (latest)

novel vector
#
bool isTouching = Input.touchCount > 0;
        if (isTouching)
        {
            Touch touch = Input.GetTouch(0);
            Ray ray = Camera.main.ScreenPointToRay(touch.position);
            RaycastHit hit;
            Debug.Log("Is touching: "+isTouching);
            
        if (Physics.Raycast(ray, out hit,99999))
        {
                if (touch.phase == TouchPhase.Began)
          Debug.Log("Raycast " +hit.transform.name);
        }
            
        }
    }``` I even set the distance to very high. I'm trying to do drag and drop but every video i copied doesn't work.
by drag and drop, i mean touching an object and it moves only when your finger moves
It only moves on one axis though, either on the x or the y (this is how i want it to work)
winged knot
#

Physics.Raycast won't hit 2D colliders. You'll have to find another way of detecting the object you tapped on.

novel vector
winged knot
#

You could also use the OnMouse... messages from MonoBehaviour. Despite their name, they should also work for touch iirc

novel vector
novel vector