using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
public class Test : MonoBehaviour
{
public float rotationSpeed = 5.0f; // 旋转速度
private Quaternion targetRotation;
private Quaternion startRotation;
void Start()
{
// 初始化目标旋转为当前旋转
targetRotation = transform.rotation;
}
void Update()
{
if(Input.GetMouseButton(0))
{
// 检测鼠标拖动
float mouseX = Input.GetAxis("Mouse X");
// 如果鼠标有移动
if (mouseX != 0)
{
// 计算旋转增量
float rotationX = mouseX * rotationSpeed;
Debug.Log(mouseX);
// 创建旋转四元数
Quaternion deltaRotation = Quaternion.Euler(0, -rotationX, 0);
// 更新目标旋转
targetRotation = targetRotation * deltaRotation;
}
}
// 平滑旋转到目标旋转
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * rotationSpeed);
}
}
片
12-28
2332
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-19
4090
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交