简体   繁体   English

如何计算动画师动画完成所需的时间?

[英]How to calculate time taken for an animator's animation to complete?

Is it possible to get the total time taken for an animator's animation to complete? 是否有可能获得动画师动画完成所需的总时间? Either in coroutines or in updates? 在协同程序或更新中?


public class AnimatorLoop : MonoBehaviour {

     private Animator anim;

    // Use this for initialization
    void Start () {
        anim = GetComponent<Animator>();
        StartCoroutine(PlayAnim());
    }

    // Update is called once per frame
    void Update () {

    }

    IEnumerator PlayAnim()
    {
        anim.Play("MoveForward", 0, 0);
        yield return null;
    }
}

IEnumerator PlayAnim()
{
    anim.Play("CubeForward", 0, 0);

    yield return new WaitForEndOfFrame();
    Debug.Log("current clip length = " + anim.GetCurrentAnimatorStateInfo(0).length);
}

Just had to add one line mentioning the length, which calculates the distance and speed to give time. 只需添加一行提及长度,计算距离和速度给出时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM