I want to move multiple instances of the same object with separate touch inputs. To be more specific, I have an object on the left and an object on the right. I want to move the object on the left with my left index finger, and the object on the right with my right index finger. I have this working to a degree, but I cannot figure out how to manipulate one object without interfering with the other. The script as it stands recognizes each touch as a separate touch, but I am unsure how to manipulate the movement variables for each touch event. Here is the script as it stands :
var verticalLimit : float = 1.2;
var scrollDistanceY : float;
function FixedUpdate () {
for (var i = 0; i < iPhoneInput.touchCount; ++i)
{
var hit : RaycastHit;
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
if (Physics.Raycast (ray, hit, 1000))
{
if(hit.collider.gameObject.tag == "handle")
{
if (Input.GetTouch(i).phase == TouchPhase.Began)
{
scrollDistanceY = hit.collider.gameObject.transform.localPosition.y;
}
if (Input.GetTouch(i).phase == TouchPhase.Moved)
{
var scrollDeltaY = Input.GetTouch(i).deltaPosition.y;
scrollDistanceY = Mathf.Clamp(scrollDistanceY+scrollDeltaY*Time.deltaTime*.8,-verticalLimit,verticalLimit);
hit.collider.gameObject.transform.localPosition.y = scrollDistanceY;
}
}
}
}
}