Thanks Raiden, it works. I made a Mix of your code and mine and the result is the Autoanim Tester: it reads all the animations contained in the GameObject and then it cycles using the space key:
private var cycleAnims : int = 0;
private var myAnims : Array;
function Start() {
myAnims = new Array();
for (animState in animation) {
myAnims.Add(animState.name);
}
SwitchAnims();
}
function SwitchAnims() {
animation.CrossFade(myAnims[cycleAnims]);
}
function Update() {
if (Input.GetKeyDown(KeyCode.Space)) {
cycleAnims = (cycleAnims + 1) % myAnims.length;
SwitchAnims();
}
}
I actually made a much more advanced version of this for my Advanced Animation tutorial. It allows you to blend, crossfade, stop, and play animations on the fly given a model and a list of animations. You can also set blend weights, blend timing, and a few other things.
This is a really great script. Thanks so much for sharing.
Quick question, is there a way to choose whether to loop a particular animation (or not) based upon the Loop settings of the Import (in the Inspector window)?