老版的unity动画系统顺序播放动画
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AniPlay : MonoBehaviour {
Animation ani;
List<string> list;
// Use this for initialization
void OnEnable()
{
ani = GetComponent<Animation>();
list = new List<string>();
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());
}
}
}
}