Unity 2D Touch drag specific Object
I am currently trying to build a 2D game with unity. I want the user to be able to drag objects around the screen..
Currently I have attached this script (found on Unity Documentation) to a gameObjectPrefab.
 public GameObject cube;
     // Update is called once per frame
         public float speed = 0.1F;
         void Update() {
             if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved) {
                 Vector2 touchDeltaPosition = Input.GetTouch(0).deltaPosition;
                 cube.transform.Translate(touchDeltaPosition.x * speed, touchDeltaPosition.y * speed, 0);
             }
         }
It works perfectly, however, this drags ALL the gameobject with the script attached to it. How can I write c#-code to only move the object which the touch/finger is currently touching and going to be dragging?
Thanks in advice!
               Comment
              
 
               
              Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                