In the app, which displays objects from a bird's eye view, recognizes the touch as well as the finger movement but the zoom functionality remains off.
So in the end nothing happens except that the fingers and the movements are recognized.
I don't understand why this is happening.
using UnityEngine;
public class ViewerCameraController : MonoBehaviour
{
private Camera cam;
private RaycastHit raycastHit;
public Collider col;
public List<GameObject> objects;
Vector3 touchStart;
public float zoomOutMin = 1;
public float zoomOutMax = 8;
private void Awake()
{
}
// Start is called before the first frame update
void Start()
{
cam = GetComponent<Camera>();
}
// Update is called once per frame
void Update()
{
if (Input.GetMouseButtonDown(0))
{
touchStart = Camera.main.ScreenToWorldPoint(Input.mousePosition);
}
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 prevMagnitude = (touchZeroPrevPos - touchOnePrevPos).magnitude;
float currentMagnitude = (touchZero.position - touchOne.position).magnitude;
float difference = currentMagnitude - prevMagnitude;
zoom(difference * 2.01f);
}
else if (Input.GetMouseButton(0))
{
Vector3 direction = touchStart - Camera.main.ScreenToWorldPoint(Input.mousePosition);
Camera.main.transform.position += direction;
}
zoom(Input.GetAxis("Mouse ScrollWheel"));
}
void zoom(float increment)
{
Camera.main.orthographicSize = Mathf.Clamp(Camera.main.orthographicSize - increment, zoomOutMin, zoomOutMax);
}
}```
