Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

How can i get correct normalizedTime for receive a animation event.

Discussion in 'Animation' started by OldKing_Wang, May 10, 2019.

  1. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    Hi

    i have some problem when try to simple an animation.

    the code is below:

    Code (csharp):
    1.  
    2. private IEnumerator DoSampleEachAnimation(AnimationClip _clip,...)
    3. {
    4.     var totalFrame = Mathf.CeilToInt(_clip.frameRate * _clip.length);
    5.     // Mathf.CeilToInt & Mathf.FloorToInt & Math.RoundToInt are all not working
    6.     var totalFrameFloat = _clip.frameRate * _clip.length;
    7.     _animator.speed = 0;
    8.  
    9.     for (var nowFrame = 0; nowFrame < totalFrame; nowFrame++)
    10.     {
    11.         _animator.Play("Simple", 0, nowFrame / totalFrameFloat);
    12.         yield return 0;
    13.         //Do Some Sample Logic Here
    14.     }
    15.  
    16. }
    17.  
    upload_2019-5-11_0-5-34.png

    upload_2019-5-11_0-6-34.png

    the animation frameRate is 30 , when the clip length is "1:19", i can't receive the animation event attach at 0:08, but if the clip length is "1:15" i can receive it .

    so , how can i get correct normalizedTime for receive a animation event.

    thanks