脚本挂在相机下,相机在非正交下有选中和缩放功能;相机在正交下有缩放和平移功能。
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 GameO
Unity TouchCamera:实现相机触摸操作

本文介绍如何通过Unity的TouchCamera脚本,实现相机在非正交视图下的选中、缩放和旋转,以及在正交视图下的缩放和平移功能。
最低0.47元/天 解锁文章
971





