如何在某些事件中每次使用动画师一次玩动画?

问题描述 投票:3回答:1

我知道animator.Play("anim")将播放动画,取决于动画片段是否循环播放,一次,默认等。我想每次调用animator.Play("anim")或按任何按钮时播放动画,它应该播放动画一次并且应该停止播放动画取消选中动画片段中的循环时间选项但是,我的问题是,如果我再次调用animator.Play("anim"),则动画不会播放;我也不想使用任何参数来触发动画,因为只需播放一个简单的动画就可以了。示例: - 有关更多说明,我创建了一个动画,并将下面的脚本附加到动画对象,并在动画片段中进行了以下调整。

enter image description hereenter image description hereenter image description here

void Update ()
{
    if (Input.GetButtonDown("Jump"))
    {
        GetComponent<Animator>().Play("New Animation");
        print("Should Play");
    }
}

当我按空格键(“跳转”)时,动画只播放一次,如果我再次按空格键则不播放。我不知道怎么做,也许我错过了什么。

animation unity3d
1个回答
1
投票

使用下面的代码播放动画并立即重置动画状态:

    GetComponent<Animator>().Play("New Animation",  -1, 0f);

资料来源:https://answers.unity.com/questions/623878/how-to-restart-mecanim-state-animation-or-play-it.html

© www.soinside.com 2019 - 2024. All rights reserved.