Unity 基础 之 DoTween 简单处理旋转 360 度为什么没有反应的情况
目录
Unity 基础 之 DoTween 简单处理旋转 360 度为什么没有反应的情况
一、简单介绍
Unity中的一些基础知识点。
本节简单整理在使用 DoTween 进行旋转 360 度的时候,竟然没有反应的情况的简单处理解决方法,如果你有新的方式也可以留言,多谢。
二、解决原理
旋转 360 度没有效果反应,是因为 DOLocalRotate 第三个参数默认是 RotateMode.Fast ,会忽略超过360的角度,然后就不会旋转,使用RotateMode,.FastBeyond360 就可以360 旋转了。
三、效果预览
三、未处理前的代码
using UnityEngine;
using DG.Tweening;
namespace XANTest {
public class TestDoTweenRotation : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
DGRotation(Vector3.right * 360, 1);
}
}
void DGRotation(Vector3 angle, float time) {
this.transform.DOLocalRotate(angle,time);
}
}
}
四、处理后,可以 360 旋转的代码
using UnityEngine;
using DG.Tweening;
namespace XANTest {
public class TestDoTweenRotation : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
DGRotation(Vector3.right * 360, 1);
}
}
void DGRotation(Vector3 angle, float time) {
this.transform.DOLocalRotate(angle,time,RotateMode.FastBeyond360);
}
}
}
附注:
SetEase(Ease.Linear) 设置成线性速率,旋转速度均匀,否则会有停止前的减速