Accessing Array of Animations from Script

Hi, I’ve imported a an FBX object which has several animations. In the inspector, it displays all the animations as a list as expected, however I’m looking to code a general solution so that I can iterate through each animation once the last has completed - so I don’t want to reference them by name, rather by index (as I’ll be repeating this process for several scenes). So, I’m trying to access the array the anims are listed in. So, rather than say:

referenceToAnimation.Play ("Animation1");

…I’d play it by saying

referenceToAnimation.Play ( animation[0] );

…but I’m struggling to actually access the animation array through code. Can anyone assist?

Thanks

This is misleading as you actually can’t access the array you see in the inspector programmatically.

What you could do is create an array of animation clips in your script and do the following:

public Animation referenceToAnimation;
public AnimationClip[] clips;
int _currClip = 0;

void OnAnimationComplete() //you could call this by adding an animation event at the end of all of your animations
{
    _currClip++;
    if(_currClip == clips.Length) return; //avoid out of scope exception
    referenceToAnimation.clip = clips[_currClip];
    referenceToAnimation.Play();
 }

Hope that helps

==