- Home /
Animation sets via array lookup
Hi everyone,
I am looking at using animations which are stored within an array, so for example, I have a game which requires the user to select a set of actions for their moves, these are stored within an array, then the avatar cycles through each animation one after the other.
Is there a way to achieve this easily? It needs to be as dynamic as possible to allow a player to continually add actions to the list.
Any guidance would be greatly appreciated.
Answer by TonyLi · Aug 16, 2013 at 01:54 PM
In Legacy, your avatar will have an Animation component. Use AddClip to add clips to the component and RemoveClip to remove them. Call Play() or CrossFade() to play them, and check IsPlaying to know when they're done so you can remove them if you want.
In Mecanim, it's currently difficult to add and remove animations at run-time. You should probably create a Animator Controller (state machine) containing all the possible states, and use parameters to transition between them.
Thanks for the advice on this, I am still using the legacy version so it sounds straight forward to put together.
I will be looking at moving towards using meca$$anonymous$$ going forwards after I build the proof of concept. The animation sets are around 100 variations, so it would be a challenge to use a state machine build
Good luck on it. When you move to $$anonymous$$ecanim, it shouldn't be too bad. As a simple pass, you could drag all your animations into the state machine and have a single int parameter that transitions to them from Any State.