I created a simple zoom and pan script for 2D and the zoom function works just fine but when i try the test the right-click pan unity freezes and I have to do a force-shutdown. Pardon my low scripting ability, this may not be the most efficient way to do what I am trying to do, which is to have several size options for my main camera, and allow it to be panned
using UnityEngine;
using System.Collections;
public class mainCamera : MonoBehaviour
{
public int zoomSetting = 1;
public float Default = 4.979221f;
public float zoom1 = 2;
public float zoom2 = 1;
public bool canPan = false;
public float horizontalSpeed = 0.5f;
public float verticalSpeed = 0.5f;
// Use this for initialization
void Start()
{
Camera.main.orthographicSize.Equals(Default);
canPan = false;
}
// Update is called once per frame
void Update()
{
if (zoomSetting == 1)
{
Camera.main.orthographicSize = Default;
canPan = false;
}
if (zoomSetting == 2)
{
Camera.main.orthographicSize = zoom1;
canPan = true;
}
if (zoomSetting == 3)
{
Camera.main.orthographicSize = zoom2;
canPan = true;
}
if (zoomSetting > 3)
{
zoomSetting = 3;
}
if (zoomSetting < 1)
{
zoomSetting = 1;
}
if (Input.GetAxis("Mouse ScrollWheel") > 0f)
{
zoomSetting = zoomSetting + 1;
}
if (Input.GetAxis("Mouse ScrollWheel") < 0)
{
zoomSetting = zoomSetting - 1;
}
if (canPan == true)
{
while (Input.GetMouseButtonDown(1))
{
float x = horizontalSpeed * Input.GetAxis("Mouse X");
float y = verticalSpeed * Input.GetAxis("Mouse Y");
transform.Translate(x, y, 0);
}
}
}
}