- Home /
Question by
hawken · Jan 19, 2014 at 08:15 AM ·
animationanimationsclipanimationstate
Get list of animation clips
I'd like to play clips I have in Animation Component randomly.
Is it possible to generate a list of animations names and then choose one randomly to play (JS)?
I've tried a few approaches, currently I have the following:
import System.Collections.Generic;
var patternID : List.<String>;
function Start () {
for (var state : AnimationState in animation) {
patternID.Add(state.name);
}
}
function RandomPatternChoice() {
var randNum : int = Random.Range(0,patternID.Count);
animation.Play(patternID[randNum], PlayMode.StopAll);
}
But the Console tells me the Component should be marked as Legacy (not possible, animation clip made in Unity), and the List doesn't populate with the clips (the FOR works, goes though all the clips).
Comment
Answer by Coimbra79 · Oct 05, 2017 at 05:32 PM
Or try 'state.clip.name' (row 6)
i wrote:`public Animation mAnim; string[] anims; // Use this for initialization void Start () { anims = new string[mAnim.GetClipCount ()]; int index = 0; foreach (AnimationState mState in mAnim) { anims [index] = mState.clip.name; index++; } }
`