- Home /
 
               Question by 
               bronxdroid · Aug 05, 2014 at 12:00 AM · 
                androidtouchtouchscreenmultitouchmulti-touch  
              
 
              Move 2 objects at the same time
I need to move 2 objects at the same time with different fingers, for unity2d confing and build for android devices.
If I have 1 finger on the screen, the object moves correctly. The problem is that if I have two fingers on the screen and move the two, the first hit object moves with difficulty.
Here the code:
 public class AndroidPlayerControler5 : MonoBehaviour {
 
 public float speed=0.01f;
 
 public Transform Player01;
 public Transform Player02;
 Rect halfLeft = new Rect(0,0, Screen.width / 2, Screen.height);
 Rect halfRight = new Rect(Screen.width/2,0F,Screen.width/2,Screen.height);
 
 void FixedUpdate(){
 
 
 
 if (Input.touchCount > 0) {
 for(int i = 0; i < Input.touchCount; i++ ) {
     Touch theTouch = Input.GetTouch(i);
     int fingerId = theTouch.fingerId;
                 
                 
                 
 if (halfLeft.Contains(theTouch.position) && theTouch.phase == TouchPhase.Moved && (fingerId==0||fingerId==1) ) {
 
 Vector2 touchDeltaPositionL = theTouch.deltaPosition;
                     
 Player01.transform.Translate(0,touchDeltaPositionL.y * speed, 0);
 
 }
 
 if (halfRight.Contains(theTouch.position) && theTouch.phase == TouchPhase.Moved && (fingerId==0||fingerId ==1)) {
                     
 Vector2 touchDeltaPositionR =theTouch.deltaPosition;
                     
 Player02.transform.Translate(0,touchDeltaPositionR.y * speed, 0);
                 
 }
                 
             
 }            
             
             
 }
 
 }
     
 }
thank you, and sorry for my english
               Comment
              
 
               
              Hello @bronxdroid, have you been able to come up with a working solution? Would appreciate your feedback if so. Cheers.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                