- Home /
 
               Question by 
               gellihorvath · Jul 30, 2020 at 11:43 PM · 
                c#unity 2dtouch controlsunity remotephone  
              
 
              I can't make drag and drop system work.
Hi Guys! I have a simple Scene with one GameObject and I would like to play around with it and get to know the phone input system, but unfortunately I can't make it work. In the unity remote controll the gameobject just staying in one place or with another scrip it just goes to the centre of the screen. I attach the two script.
         if (Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             Vector3 touchPosition = touch.position;
             touchPosition.y = 0;
             Debug.Log(touchPosition.x);
             transform.position = Camera.main.ScreenToWorldPoint(touchPosition);
 
             if (touch.phase == TouchPhase.Ended)
                 r2d.velocity = Vector2.zero;
         }
With this script it just goes to the centre of the screen it doesn't matter where I touch the screen.
         if (Input.touchCount > 0)
         {
             Touch touch = Input.GetTouch(0);
             Vector2 touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
             if(touch.phase == TouchPhase.Began)
             {
                 Collider2D touchedCollider = Physics2D.OverlapPoint(touchPosition);
                 if(col == touchedCollider)
                 {
                     Debug.Log("touching");
                     moveAllowed = true;
                 }
             }
             if(touch.phase == TouchPhase.Moved)
             {
                 if(moveAllowed == true)
                 {
                 transform.position = new Vector2(touchPosition.x, touchPosition.y);
                 }
             }
             if(touch.phase == TouchPhase.Ended)
             {
                 moveAllowed = false;
             }
         }
With this script I wanted to make a "drag and drop" system but with this script it doesn't work at all.
I hope you can help me Guys. Thank you!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                