unity旧版本Animation顺序播放动画

unity旧版本Animation顺序播放动画_第1张图片
Animation添加AnimationClip后在物体添加以下脚本

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,animation)