【问题标题】:How to wait for an animation to finished in Unity C# [duplicate]如何在Unity C#中等待动画完成[重复]
【发布时间】:2017-08-10 07:12:44
【问题描述】:

我想在设置触发器后等待动画剪辑完成。

private void Start()
{
    anim = GetComponent<Animator>();
}


private IEnumerator Die()
{
    // Play the animation for getting suck in
    anim.SetTrigger("Shrink")      

    // Wait for the current animation to finish
    while (!anim.IsInTransition(0))
    {
        yield return null;
    } 

    // Move this object somewhere off the screen

}

动画播放,但它不会等待完成,然后在 while 循环之后继续执行代码。

这是我的动画组件:

【问题讨论】:

    标签: c# unity3d animator


    【解决方案1】:

    您可以使用 Unity 的动画事件 (https://docs.unity3d.com/Manual/script-AnimationWindowEvent.html)。

    它们是可以放置在动画时间轴中的标记,允许您指定将被调用的函数。

    【讨论】:

    【解决方案2】:

    等待动画完成的方法是使用动画完成所需的时间,您可以在查看检查器的动画中找到该时间,您只需在触发动画后等待该时间即可。

    所以在你的情况下,它看起来像这样:

    private IEnumerator Die()
    {
        // Play the animation for getting suck in
        anim.SetTrigger("Shrink") 
    
        yield return new WaitForSeconds(animationTime);
    
        // Move this object somewhere off the screen
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-04-11
      • 1970-01-01
      • 1970-01-01
      • 2013-02-13
      • 2011-09-07
      • 1970-01-01
      • 1970-01-01
      • 2012-08-23
      相关资源
      最近更新 更多