I don´t know what to do, to have a perspective camera view that i can use to zoom in and out…
using System.Collections;
using UnityEngine;
public class PinchZoom : MonoBehaviour
{
public Camera mainCam;
public float perspectiveZoomSpeed = .5f;
public float orthoZoomSpeed = .5f;
void Update()
{
if (Input.touchCount == 2)
{
Touch touchZero = Input.GetTouch(0);
Touch touchOne = Input.GetTouch(1);
Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
Vector2 touchOnePrevPos = touchOne.position - touchOne.deltaPosition;
float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float touchDeltaMag = (touchZero.position - touchOne.position).magnitude;
float deltaMagnitudediff = prevTouchDeltaMag - touchDeltaMag;
if (GetComponent().orthographic)
{
GetComponent().orthographicSize += deltaMagnitudediff * orthoZoomSpeed;
GetComponent().orthographicSize = Mathf.Max(GetComponent().orthographicSize, .1f);
}
else
{
GetComponent().fieldOfView += deltaMagnitudediff * perspectiveZoomSpeed;
GetComponent().fieldOfView = Mathf.Clamp(GetComponent().fieldOfView, 20f, 89.9f);
}
}
}
}