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)
#Raycast not working in a 2d world
1 messages · Page 1 of 1 (latest)
Physics.Raycast won't hit 2D colliders. You'll have to find another way of detecting the object you tapped on.
so, i have to do it in a 3d scene. making it 2.5d?
You could also use the OnMouse... messages from MonoBehaviour. Despite their name, they should also work for touch iirc
alternatively, will 3D prefabs work in an orthographic camera view?
won't this just detect one of the touches if you have multiple fingers on the screen?