需求:求一个值单位时间内,从最大值X到0再返回到X
代码如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;public class 测试插值运动 : MonoBehaviour
{public float get;// Start is called before the first frame updatevoid Start(){float _max = 50;float _time = 2f;float _sp = 2f * _max / _time;DOTween.To(setter: value =>{get = TurnbackMovement(_max, value, _time, _sp);//Debug.Log(get);}, startValue: 0, endValue: _time, duration: _time).SetEase(Ease.Linear).OnComplete(() => { });}private float TurnbackMovement(float _max, float _currentTime, float _time,float _sp){var _num= 0f;if (_currentTime <= _time * 0.5f) _num = _max - _sp * _currentTime;else _num = _sp * (2 * _currentTime - _time);//Debug.LogError(_max+" "+_currentTime+" "+_time+" "+_sp+" "+ _num); return Mathf.Clamp(_num,0,_max);}
}
本文发布于:2024-01-27 20:04:56,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/17063570962351.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |