脚步挂在相机上
具体脚步如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotation : MonoBehaviour
{
//鼠标控制摄像机旋转方向
public Transform Target;
//旋转速度
private float SpeedX = 240;
private float SpeedY = 120;
//角度限制
private float MinLimitY = -180;
private float MaxLimitY = 180;
//旋转角度
private float mX = 180F;
private float mY = 0.0F;
//是否启用差值
public bool isNeedDamping = true;
//速度
public float Damping = 10F;
//存储角度的四元数
private Quaternion mRotation;
void LateUpdate()
{
//鼠标右键旋转
if (Input.GetMouseButton(1))
{
//获取鼠标输入
mX += Input.GetAxis("Mouse X") * SpeedX * 0.02F;
// mY -= Input.GetAxis("Mouse Y") * SpeedY * 0.02F;
//范围限制
mY = ClampAngle(mY, MinLimitY, MaxLimitY);
//计算旋转
mRotation = Quaternion.Euler(mY, mX, 0);
//根据是否插值采取不同的角度计算方式
if (isNeedDamping)
{
transform.rotation = Quaternion.Lerp(transform.rotation, mRotation, Time.deltaTime * Damping);
}
else
{
transform.rotation = mRotation;
}
}
}
//角度限制
private float ClampAngle(float angle, float min, float max)
{
if (angle < -360) angle += 360;
if (angle > 360) angle -= 360;
return Mathf.Clamp(angle, min, max);
}
}