Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

touch screen to world point

  public void MoveAction(InputAction.CallbackContext context)
    {
        Vector2 touchPos = context.ReadValue<Vector2>();

        Ray ray = Camera.main.ScreenPointToRay(touchPos);

        Plane plane = new Plane(Vector3.up, transform.position);

        float distance = 0;

        if (plane.Raycast(ray, out distance))
        {
            Vector3 pos = ray.GetPoint(distance);

            Move(pos);
        }
    }
 
PREVIOUS NEXT
Tagged: #touch #screen #world #point
ADD COMMENT
Topic
Name
1+9 =