Unity Animation顺序播放动画

老版的unity动画系统顺序播放动画 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AniPlay : MonoBehaviour {

    Animation ani;
    List list;
    // Use this for initialization
    void OnEnable()
    {
        ani = GetComponent();
        list = new List();
        foreach (AnimationState state in ani)
        {
            list.Add(state.name);
        }

        StartCoroutine(PlayAnima());

    }
    IEnumerator PlayAnima()
    {
        foreach (var item in list)
        {
            print(item);
            ani.CrossFade(item);
            yield return new WaitForSeconds(ani.GetClip(item).length);
            if (item.CompareTo(list[list.Count - 1]) == 0)
            {
                StartCoroutine(PlayAnima());
            }

        }
    }
}

 

你可能感兴趣的:(unity)