Search Unity

Question How to retrieve the total duration time in seconds of an animation clip?

Discussion in 'Scripting' started by unity2life, Aug 5, 2020.

  1. unity2life

    unity2life

    Joined:
    Jun 6, 2020
    Posts:
    19
    Given is the Animator object in the code :
    Animator animator = ... ;
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,909
    unity2life likes this.
  3. unity2life

    unity2life

    Joined:
    Jun 6, 2020
    Posts:
    19
    Thx, this helps me dude:

    Code (CSharp):
    1.     void Start()
    2.     {
    3.         //Get them_Animator, which you attach to the GameObject you intend to animate.
    4.         m_Animator = gameObject.GetComponent<Animator>();
    5.         //Fetch the current Animation clip information for the base layer
    6.         m_CurrentClipInfo = this.m_Animator.GetCurrentAnimatorClipInfo(0);
    7.         //Access the current length of the clip
    8.         m_CurrentClipLength = m_CurrentClipInfo[0].clip.length;
    9.         //Access the Animation clip name
    10.         m_ClipName = m_CurrentClipInfo[0].clip.name;
    11.     }
     
    Sarai likes this.
  4. Xwad

    Xwad

    Joined:
    May 14, 2020
    Posts:
    41
    For this i get frames/framerate value. Also for .time definition!