Get Length Of Animationclip Unity Code Example


Example: how to get clip length of animation unity


public float attackTime;
public float damageTime;
public float deathTime;
public float idleTime;

private Animator anim;
private AnimationClip clip;

// Use this for initialization
void Start () {
anim = GetComponent<Animator>();
if(anim == null)
{
Debug.Log("Error: Did not find anim!");
} else
{
//Debug.Log("Got anim");
}

UpdateAnimClipTimes();
}
public void UpdateAnimClipTimes()
{
AnimationClip[] clips = anim.runtimeAnimatorController.animationClips;
foreach(AnimationClip clip in clips)
{
switch(clip.name)
{
case "Attacking":
attackTime = clip.length;
break;
case "Damage":
damageTime = clip.length;
break;
case "Dead":
deathTime = clip.length;
break;
case "Idle":
idleTime = clip.length;
break;
}
}
}

Comments

Popular posts from this blog

C Perror Example

Converting A String To Int In Groovy

"Cannot Create Cache Directory /home//.composer/cache/repo/https---packagist.org/, Or Directory Is Not Writable. Proceeding Without Cache"