首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用冬青来缓解浮子?

如何用冬青来缓解浮子?
EN

Stack Overflow用户
提问于 2022-06-06 21:52:14
回答 2查看 3K关注 0票数 1

目标之间的“向前”价值。

这是来自于两国之间的例子。

相反,移动多维数据集,我想将“前进”值更改为0到1。

代码语言:javascript
复制
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);
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-06-06 22:31:34

您可以使用DoVirtual.Float,在此方法中不需要valueToLerp变量。

代码语言:javascript
复制
// anim.SetFloat("Forward", valueToLerp);

s.Append(DOVirtual.Float(0, 1f, 1f, v => anim.SetFloat("Forward", v)));
票数 2
EN

Stack Overflow用户

发布于 2022-06-06 22:56:12

此外,解决方案(但是来自另一个评论的DOVirtual.Float更好):

代码语言:javascript
复制
    var forwardTween = DOTween.To(
            () => anim.GetFloat("Forward"),
            (val) => anim.SetFloat("Forward", val),
            6,
            duration)
        .SetRelative()
        .SetEase(Ease.InOutQuad);
    s.Append(forwardTween);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72523817

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档