Search Unity

Question New input system touch (vector2) to collide with 3d objects with AR Fundation

Discussion in 'XR Interaction Toolkit and Input' started by RPereiraGoXplora, Nov 24, 2020.

  1. RPereiraGoXplora

    RPereiraGoXplora

    Joined:
    Dec 10, 2019
    Posts:
    11
    Hello Unity members,
    I'm having trouble to do the touch of a object with the new input system, before with the OnMouseDown in each object i could detect it, and by the name i could get the object that had the collision, but now what can i do with the new Input system?
    I'm using AR fundation, and AR Camera, maybe it's that?
    On Android platform.

    var touchPosition = context.ReadValue<Vector2>();
    var world = Camera.main.ScreenToViewportPoint(touchPosition);
    Ray ray = Camera.main.ViewportPointToRay(world);
    RaycastHit raycastHit;
    if (Physics.Raycast(ray, out raycastHit))
    {
    Debug.LogError("I'm looking at " + raycastHit.transform.name);
    }