脚本挂在相机下,相机在非正交下有选中和缩放功能;相机在正交下有缩放和平移功能。
using UnityEngine;
public class TouchCamera : MonoBehaviour
{
public bool canPan = true;
public bool canScale = true;
public MouseSettings mouseSettings = new MouseSettings(0, 10, 10);
public Range angleRange = new Range(0, 90);
public Range distanceRange = new Range(1, 1000);
//around center
public Transform target;
private Vector2 oldPos1;
private Vector2 oldPos2;
private bool m_isSinleFinger;
private Vector3 targetPan;
private Vector3 currentPan;
private Vector2 targetAngles;
private Vector2 currentAngles;
private float targetDistance;
private float currentDistance;
private bool getCurrentDA = true;
//Damper(阻尼) for move and rotate
[Range(0, 10)]
private float damper = 2;
void Start()
{
GameObject camTargetObj = GameObject.Find("Main Camera Target");
if (camTargetObj == null)
camTargetObj = new GameObject("Main Camera Target");
target = camTargetObj.transform;
currentAngles = targetAngles = transform.eulerAngles;
currentPan = targetPan = transform.position;
currentDistance = targetDistance = Vector3.Distance(transform.position, target.posit