目标之间的“向前”价值。
这是来自于两国之间的例子。
相反,移动多维数据集,我想将“前进”值更改为0到1。
using UnityEngine;
using System.Collections;
using DG.Tweening;
public class Sequences : MonoBehaviour
{
public Transform cube;
public float duration = 4;
public Animator anim;
private valueToLerp = 0;
IEnumerator Start()
{
// Start after one second delay (to ignore Unity hiccups when activating Play mode in Editor)
yield return new WaitForSeconds(1);
// Create a new Sequence.
// We will set it so that the whole duration is 6
Sequence s = DOTween.Sequence();
// Add an horizontal relative move tween that will last the whole Sequence's duration
anim.SetFloat("Forward", valueToLerp);
s.Append(cube.DOMoveX(6, duration).SetRelative().SetEase(Ease.InOutQuad));
// Insert a rotation tween which will last half the duration
// and will loop forward and backward twice
s.Insert(0, cube.DORotate(new Vector3(0, 45, 0), duration / 2).SetEase(Ease.InQuad).SetLoops(2, LoopType.Yoyo));
// Add a color tween that will start at half the duration and last until the end
s.Insert(duration / 2, cube.GetComponent<Renderer>().material.DOColor(Color.yellow, duration / 2));
// Set the whole Sequence to loop infinitely forward and backwards
s.SetLoops(-1, LoopType.Yoyo);
}
}发布于 2022-06-06 22:31:34
您可以使用DoVirtual.Float,在此方法中不需要valueToLerp变量。
// anim.SetFloat("Forward", valueToLerp);
s.Append(DOVirtual.Float(0, 1f, 1f, v => anim.SetFloat("Forward", v)));发布于 2022-06-06 22:56:12
此外,解决方案(但是来自另一个评论的DOVirtual.Float更好):
var forwardTween = DOTween.To(
() => anim.GetFloat("Forward"),
(val) => anim.SetFloat("Forward", val),
6,
duration)
.SetRelative()
.SetEase(Ease.InOutQuad);
s.Append(forwardTween);https://stackoverflow.com/questions/72523817
复制相似问题