Halp! Animation Components/List of Anims

I’m trying to write a for loop that puts a button up for each animation in the Animation component. the following code does just about everything, but it makes a list of the first animation only, since I can’t figure out how to extract the name of each anim in the list. What I need is something like go.animation*.clip.name, but I keep getting castTo exceptions when I try that.*
Anyone know how to access the names of the animations by position in the list?
```
*var go : GameObject;

function OnGUI{
for (var i in go.animation){
var thisAnimClip = go.animation.clip.name;
print(thisAnimClip);
if(GUILayout.Button(“”+thisAnimClip)){
go.animation.CrossFade(thisAnimClip);
}
}
}*
```

It just seems strange that given the Animation (which contains the clips) and an integer, I can’t get the name of a clip in a string somehow.

var go : GameObject;

function OnGUI{
for (var anim : AnimationState in go.animation){
var thisAnimClip : string = anim.name;
print(thisAnimClip);
   if(GUILayout.Button(thisAnimClip)){
      go.animation.CrossFade(anim);
   }
}
}

The syntax could be off, but that should be close. Clip represents the active clip, you are iterating through the clips already, so grab the current iteration.

Also it is extremely beneficial for future review and for others reviewing your code to explicitly declare what each variable is. It’ll save you hours/days/weeks in debugging.

Awesome! A few minor syntax things, and boom, perfect!

Thanks for the help, Ntero!