How can I play a few animation clips one after another?

How can I play a few animation clips one after another? I have clipA, clipB and clipC. In my code, I want to play these clips randomly, but one after another. So it could start from clipB first, then after clipB is done playing, go on to play clipC, then clipA and so on.

I have tried PlayQueued. But it doesn’t work as I expected it to be.

Here’s my usage:

animation.PlayQueued("clipB", QueueMode.CompleteOthers); 
animation.PlayQueued("clipA", QueueMode.CompleteOthers); 
animation.PlayQueued("clipC", QueueMode.CompleteOthers); 

But this doesn’t play the clips at all.

Here is a custom version:

IEnumerator QueueAnim(params AnimationClip[] anim){
   int index = 0;
   animation.clip = anim[index];
      yield return new WaitForSeconds(anim[index].length);
      animation.clip = anim[index];

Then you call it as such:

void Update(){
    animQueue = false;

I am doing this on top of my head with no Unity to try so there could be issues…
You can pass as many animation clips as you wish since it uses params.
But again, it could be all wrong…

Here is a function I made that works for me:

void RandomizeAnimation (GameObject crowd) {
		int RndAnim = UnityEngine.Random.Range (0, Animations.Length);
		int RndSpeed = UnityEngine.Random.Range (1, 100);
		float RndFade = UnityEngine.Random.Range (0.1f, 1f);
		crowd.animation.CrossFadeQueued("anim"+RndAnim, RndFade, QueueMode.CompleteOthers);
		crowd.animation["anim"+RndAnim].speed = RndSpeed;

The gameobject have many animations, all animations are named anim1, anim2, anim3 etc.

I hope you can understand it, if you have any question just ask :slight_smile: