- Home /
 
 
               Question by 
               mmyoonsin94 · Apr 18, 2018 at 01:25 PM · 
                move an objectdrag objects  
              
 
              The gameobject is out the screen of mobile when being moved by finger
Yes, I able to move the gameobject from one position to the other, but when I did it , the gameobject is out of my mobile screen and can't be seen. The gameobject should be on the position of screen where I last touched when I move the gameobject. Here is my code so far:
        if (Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             Debug.Log(Input.touchCount);
 
             ray = arCamera.ScreenPointToRay(touch.position);
             //position = arCamera.ScreenToWorldPoint(touch.position);
 
             switch (touch.phase)
             {
                 case TouchPhase.Began:
                     Debug.Log("Touch began");
                     Debug.DrawRay(ray.origin, ray.direction * 20, Color.red);
 
                     if (Physics.Raycast(ray, out hit, Mathf.Infinity))
                     {
                         if (hit.collider.gameObject == jar_lid) {
                             startPos = arCamera.WorldToScreenPoint(touch.position);
                             deltaX = startPos.x;
                             deltaY = startPos.y;
                             Debug.Log("StartPoint:" + deltaX + " " + deltaY);
                         }
                     }
                     break;
                     
                 case TouchPhase.Moved:
                     if (hit.collider.gameObject == jar_lid)
                     {
                         position = arCamera.WorldToScreenPoint(touch.position);
                         rb.MovePosition(new Vector2(position.x-deltaX, position.y-deltaY));
                         rb.useGravity = true;
                     }
                     break;
 
                 case TouchPhase.Ended:
                     moveAllowed = false;
                     break;
             }
         }
 
              
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Rigidbody Not Move 0 Answers
Delay when drag object from mouse cursor 0 Answers
Semi Dynamic Shadows 1 Answer
Transform.Position stop? 1 Answer