Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Checking the frame in the animation

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

  1. malnar1996


    Oct 31, 2010
    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


    Feb 10, 2010
    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);