Hello everyone does anyone know why this script makes multi touch behave weird. Whoever puts their finger first they can move flawlessly. Second touch can still move but very stiff and laggy and not 1 to 1. Soon as first touch is lifted now the second touch player can move flawlessly…and vice versa. Please advise thank you.
using UnityEngine;
using System.Collections;
public class TouchDrag : 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);
}
}
}
}
}