1.按下鼠标右键可以实现摄像机上下左右旋转
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CameraRotate : MonoBehaviour
{
//旋转速度
public float rotationSpeed = 5f;
//上下旋转角度限制
public float maxVerticalAngle = 90f;
public float minVerticalAngle = -90f;
//旋转缓冲速度
public float lerpSpeed = 10f;
private float targetRotationX = 0f;
private float targetRotationY = 0f;
void Update()
{
if (Input.GetMouseButton(1))
{
// 获取鼠标输入的旋转增量
float rotationXInput = -Input.GetAxis("Mouse Y");
float rotationYInput = Input.GetAxis("Mouse X");
// 根据旋转速度进行摄像机的旋转
targetRotationX += rotationXInput * rotationSpeed;
targetRotationY += rotationYInput * rotationSpeed;
// 对上下旋转角度进行限制
targetRotationX = Mathf.Clamp(targetRotationX, minVertical
因篇幅问题不能全部显示,请点此查看更多更全内容