Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We've updated our Terms of Service. Please read our blog post from Unity CTO and Co-Founder Joachim Ante here
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

get time of animation clip in Animation(legacy) component?

Discussion in 'Animation' started by FeastSC2, Nov 1, 2018.

  1. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    492
    I would like to get the playtime of an animation clip, this way I can stop playing the animation then restart it at a later time when I'm unpausing the game.

    I mean the animation clip used by an Animation(legacy) component and not an Animator.

    How can I access that information?
     
  2. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    492
    Does no one know this?
     
  3. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,601
    All animation should stop if you pull Time.timeScale to 0 and should continue when you put back the original value.
    Also you can pause if you set the individual animation.enable = false; and should continue when you set it true.

    Does any of these work for you?

    BTW: animation.clip.length;
    https://docs.unity3d.com/ScriptReference/AnimationClip-length.html
     
  4. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    492
    Time.timescale doesn't work and animation.enable sets the animation back to the start. The length was to get how long the whole animation lasts and not where it's at in that animation.

    So I still don't know how to do it.. ;s
     
  5. Lurking-Ninja

    Lurking-Ninja

    Joined:
    Jan 20, 2015
    Posts:
    2,601
    FeastSC2 likes this.
  6. FeastSC2

    FeastSC2

    Joined:
    Sep 30, 2016
    Posts:
    492

    That works great, thanks! AnimationState has all the interesting information. Time.timeScale set to 0 does not stop the animation but that's a good thing because then animation on UI would be stopped when the game is paused. If it's a bug it's a good one.