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

Checking the frame in the animation

Discussion in 'Scripting' started by malnar1996, Dec 5, 2010.

  1. malnar1996

    malnar1996

    Joined:
    Oct 31, 2010
    Posts:
    31
    I was wondering if there is a way to check on what frame in the animation am I.
    I hope you understand.
    If my animation is at 20th frame, I want to check that with my script (it check every frame)

    I used to work in flash and it was very simple to check on what frame are you (var curframe = some_movie_clip.currentframe)

    That's all.
    I want to put a curent frame of the animation in a variable.
     
  2. Vicenti

    Vicenti

    Joined:
    Feb 10, 2010
    Posts:
    664
    There are no frames in Unity.

    Instead, you have animation times in seconds -

    Code (csharp):
    1. var ratio = animation["clip"].time / animation["clip"].length;
    From that you can derive the frame number, though really that's usually just an unnecessary extra operation, as the ratio is powerful enough for most uses-
    Code (csharp):
    1. var frame = ratio * (framesInAnimation);