I use this script to zoom in and out 2DCamera, but when I zoom I can not move image by one finger how could I did with it…
using UnityEngine;
using System.Collections;
//Creating by Neodrop
//neodrop@unity3d.ru
[RequireComponent(typeof(Camera))]
public class Zoomer_2DCam : MonoBehaviour {
public float stepPerSecond = 1f, orthoMin = 3f, orthoMax = 6f;
float lastDistance = 0f;
void FixedUpdate()
{
if (iPhoneInput.touchCount != 2)
{
lastDistance = 0;
return;
}
if (iPhoneInput.touches[0].phase != iPhoneTouchPhase.Moved && iPhoneInput.touches[1].phase != iPhoneTouchPhase.Moved)
{
lastDistance = 0;
return;
}
iPhoneTouch[] touch = iPhoneInput.touches;
float distance = Vector2.Distance(touch[0].position, touch[1].position);
if (distance == lastDistance) return;
float touchDistance = (touch[1].position - touch[0].position).magnitude;
float lastTouchDistance = ((touch[1].position - touch[1].deltaPosition) - (touch[0].position - touch[0].deltaPosition)).magnitude;
float deltaPinch = touchDistance - lastTouchDistance;
camera.orthographicSize += deltaPinch * stepPerSecond * Time.deltaTime;
if (camera.orthographicSize < orthoMin) camera.orthographicSize = orthoMin;
else if (camera.orthographicSize > orthoMax) camera.orthographicSize = orthoMax;
lastDistance = distance;
}
}
thx for your comment!!!