A Script to test animations

Hi,

I was working on a simple script to play all the animations of an GameObject for testing purposes, but I can’t make it.

The code looks something like this:

function Awake() {
	for (animState in animation) {
		animation.PlayQueued(animState.name, QueueMode.CompleteOthers);
		print(animState.name);
	}
}

But when it runs, it locks, Does anybody know the right way of doing that? Thanks [/code]

Here’s one option:

private var cycleAnims : int = 0;
private var myAnims : String[];

function Start() {
  myAnims = ["anim1", "anim2", "anim3", "anim4", "anim5"];
  SwitchAnims();
}

function SwitchAnims() {
  animation.CrossFade(myAnims[cycleAnims]);
}

function Update() {
  if (Input.GetKeyDown(KeyCode.Space)) {
    cycleAnims = (cycleAnims + 1) % myAnims.length;
    SwitchAnims();
  }
}

-Raiden

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. :slight_smile:

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)?

Thanks for the script, just wondering what AnimState is in the code there?

Kind of a late reply but:

private var cycleAnims : int = 0; 
private var myAnims : Array; 

function Start() { 
  myAnims = new Array(); 
  
  for (animState : AnimationState  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(); 
  } 
}