using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 相机脚本,平滑移动
/// </summary>
public class CameraFollowCtrl : MonoBehaviour
{
/// <summary>
/// 2D镜头缩放范围
/// </summary>
public float maxSD = 20.0f;
public float minSD = 1f;
public float zoooSpeed = 0.3f;
private Vector2 start;
private Vector2 drag;
private Vector3 pos;
private bool isDrag;
private void OnGUI()
{
if(Event.current.type == EventType.MouseDown)
{
start = Event.current.mousePosition;
}
if(Event.current.type == EventType.MouseDrag)
{
drag = Event.current.mousePosition;
Vector3 vecStart = Camera.main.ScreenToWorldPoint(new Vector3(start.x, -start.y, 0));
Vector3 vecdrag = Camera.main.ScreenToWorldPoint(new Vector3(drag.x, -drag.y, 0));
pos = vecdrag - vecStart;
start = drag;
isDrag = true;
}
else
isDrag = false;
unity相机远近缩放和拖拽移动
最新推荐文章于 2024-01-08 11:36:31 发布