Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Unity C中等待动画完成#_C#_Unity3d_Animator - Fatal编程技术网

C# 如何在Unity C中等待动画完成#

C# 如何在Unity C中等待动画完成#,c#,unity3d,animator,C#,Unity3d,Animator,我想在设置触发器后等待动画剪辑完成 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

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

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

}
private void Start()
{

anim=GetComponent

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

所以在你的例子中,它看起来是这样的:

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

}

可以使用Unity的动画事件()

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