首页 > 解决方案 > 在 Unity 中同步时间和动画的问题

问题描述

我的问题是我想根据用户猜测的时间播放不同的动画。由于 Unity 更新的性质,我当前的代码不起作用。不知道如何改变它。不想把它变成协程,因为我必须更改很多以前的代码。将非常感谢您的帮助。

if(userGuessing)
{
    timerText.gameObject.SetActive(true);
    timer -= Time.deltaTime;
    timerText.text = timer.ToString("0.00");
    Debug.Log(timer);
}

if(timer > 90)
{
    bossArmature.animation.Play("BossVeryHappy", -1);
}
else if(timer > 70 && timer < 90)
{
    bossArmature.animation.Play("BossHappy", -1);
}
else if(timer > 50 && timer < 70)
{
    bossArmature.animation.Play("BossNeutral", -1);
}
else if(timer > 30 && timer < 50)
{
    bossArmature.animation.Play("BossAngry", -1);
}

标签: unity3d

解决方案


您可以使用动画条件来控制基于您的计时器的行为,只需将 Animator 的 'Timer' 参数设置为当前计时器值。然后使用 LessThan 条件来处理不同的动画。

bossArmature.animation.SetFloat("Timer", timer);

然后它可能看起来像这样


推荐阅读