检查动画剪辑完成有 [英] Check if animation clip have finish

查看:173
本文介绍了检查动画剪辑完成有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是更新的内部简单code。可悲的是它不工作形成了我。事件中,我已设置自动换行模式到永远钳制!

This is the simple code inside of update. sadly it is not working form me. Event i have set Wrap Mode to clamp Forever!

 if (trainGO.GetComponent<Animation>()["Start"].time >= trainGO.GetComponent<Animation>()["Start"].length)
 {
      blackTrain.SetActive(true);
      redTrain.SetActive(false);
 }

我如何检查动画剪辑完成有这样我可以做一些工作。 我不想用WaitForSeconds方法。,因为我wroking的时间,每一个新的动画将播放时间

How can I check that animation clip have finish so that i can do some work. I don't want to use WaitForSeconds method. Cause I am wroking on Time and each time a new animation will be played

推荐答案

基本上是这样的...

Basically like this ...

PlayAnimation(); // Whatever you are calling or using for animation
StartCoroutine(WaitForAnimation(animation));

private IEnumerator WaitForAnimation ( Animation animation )
    {
    while(animation.isPlaying)
        yield return null;

    // at this point, the animation has completed
    // so at this point, do whatever you wish...
    Debug.Log("Animation completed");
    }

您可以平凡谷歌的上千QA关于这个例如, http://answers.unity3d.com/answers/37440/view.html

You can trivially google thousands of QA about this example, http://answers.unity3d.com/answers/37440/view.html

如果你不完全理解的协同程序在Unity,退一步审查的任何部分8000充分的初级教程和QA关于团结协同程序在网络上的。

If you do not fully understand coroutines in Unity, step back and review any of the some 8,000 full beginner tutorials and QA regarding "coroutines in Unity" on the web.

这是真的在Unity完成检查动画的方式 - 这是一个标准的技术,真的没有替代

This is really the way to check an animation is finished in Unity - it's a standard technique and there's really no alternative.

您提到要做好更新的东西() ...你可能做这样的事情:

You mention you want to do something in Update() ... you could possibly do something like this:

private Animation trainGoAnime=ation;

public void Update()
    {

    if ( trainGoAnimation.isPlaying() )
        {
        Debug.Log("~ the animation is still playing");
        return;
        }
    else
        {
        Debug.Log("~ not playing, proceed normally...");
        }
    }

我强烈建议你只是一个协程做到了;你会最终以节,如果你尝试始终使用更新。希望它帮助。

I strongly encourage you to just do it with a coroutine; you'll end up "in knots" if you try to "always use Update". Hope it helps.

仅供参考,你还别说的实际上的情况是:在(时间/时钟单独运行时)我要玩,为什么我使用更新检查时间的动画,多数民众赞成,并相应地运行动画指定的时间

FYI you also mention "actually the scenario is: at specified time (Time/clock separately running). I have to play an animation thats why i am using update to check the time and run animation accordingly"

这是很容易做到的,说你想从现在3.721秒...

This is very easy to do, say you want to run the animation 3.721 seconds from now...

private float whenToRunAnimation = 3.721;

这是如此简单!

    // run horse anime, with pre- and post- code
    Invoke( "StartHorseAnimation", whenToRunAnimation )

private void StartHorseAnimation()
  {
  Debug.Log("starting horse animation coroutine...");
  StartCoroutine(_horseAnimationStuff());
  }

private IENumerator _horseAnimationStuff()
  {
  horseA.Play();
  Debug.Log("HORSE ANIME BEGINS");
  while(horseA.isPlaying)yield return null;
  Debug.Log("HORSE ANIME ENDS");
  ... do other code here when horse anime ends ...
  ... do other code here when horse anime ends ...
  ... do other code here when horse anime ends ...
  }

这篇关于检查动画剪辑完成有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆