Im hoping someone can help me with this.
I have a Orthographic camera and I would like to be able to zoom in and out with touch controls.
I’ve been using a script for CameraZoomPinch which works great for a Perspective Camera but I cant seem to modify it correctly for an Orthographic Camera.
A Perspective camera uses fieldOfView to zoom and a Orthographic camera uses size to zoom
using UnityEngine; using System.Collections;
public class CameraZoomPinch : MonoBehaviour
{
public int speed = 4;
public Camera selectedCamera;
public float MINSCALE = 2.0F;
public float MAXSCALE = 5.0F;
public float minPinchSpeed = 5.0F;
public float varianceInDistances = 5.0F;
private float touchDelta = 0.0F;
private Vector2 prevDist = new Vector2(0,0);
private Vector2 curDist = new Vector2(0,0);
private float speedTouch0 = 0.0F;
private float speedTouch1 = 0.0F;
// Use this for initialization
void Start ()
{
}
// Update is called once per frame
void Update ()
{
if (Input.touchCount == 2 && Input.GetTouch(0).phase == TouchPhase.Moved && Input.GetTouch(1).phase == TouchPhase.Moved)
{
curDist = Input.GetTouch(0).position - Input.GetTouch(1).position; //current distance between finger touches
prevDist = ((Input.GetTouch(0).position - Input.GetTouch(0).deltaPosition) - (Input.GetTouch(1).position - Input.GetTouch(1).deltaPosition)); //difference in previous locations using delta positions
touchDelta = curDist.magnitude - prevDist.magnitude;
speedTouch0 = Input.GetTouch(0).deltaPosition.magnitude / Input.GetTouch(0).deltaTime;
speedTouch1 = Input.GetTouch(1).deltaPosition.magnitude / Input.GetTouch(1).deltaTime;
if ((touchDelta + varianceInDistances <= 1) && (speedTouch0 > minPinchSpeed) && (speedTouch1 > minPinchSpeed))
{
selectedCamera.size/*fieldOfView*/ = Mathf.Clamp(selectedCamera.size/*fieldOfView*/ + (1 * speed),15,90);
}
if ((touchDelta +varianceInDistances > 1) && (speedTouch0 > minPinchSpeed) && (speedTouch1 > minPinchSpeed))
{
selectedCamera.size/*fieldOfView*/ = Mathf.Clamp(selectedCamera.size/*fieldOfView*/ - (1 * speed),15,90);
}
}
}
}
If I change fieldOfView to size I get an error:
UnityEngine.Camera’ does not contain a definition for size' and no extension method
size’ of type `UnityEngine.Camera’ could be found (are you missing a using directive or an assembly reference?)
puzzling I could be wrong but I thought the Orthographic camera has a size variable