- Home /
 
Drag-and-drop dot on mobile 2D
I got this code.
 Vector3 dist;
     float posX;
     float posY;
 
     void OnMouseDown()
     {
         dist = Camera.main.WorldToScreenPoint(transform.position);
         posX = Input.mousePosition.x - dist.x;
         posY = Input.mousePosition.y - dist.y;
 
     }
 
     void OnMouseDrag()
     {
         Vector3 curPos =
                   new Vector3(Input.mousePosition.x - posX,
                   Input.mousePosition.y - posY, dist.z);
 
         Vector3 worldPos = Camera.main.ScreenToWorldPoint(curPos);
         transform.position = worldPos;
     }
 }
 
               When i hold the circle with the mouse and drags, the circle follows. How can i do the exact same thing with touch inputs? Appreciate answers!
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Touch drag 2D object in x axis 1 Answer
How do I re-enable input after dragging off iPad screen? 0 Answers
how can i touch the fast objects ? 0 Answers
Move an object to Input.Touch location 0 Answers
Simultaneous Touch Drag Controls 0 Answers