Unity Animation顺序播放动画

老版的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());
            }

        }
    }
}

 

    原文作者:会思考的猴子
    原文地址: https://blog.csdn.net/qq_39097425/article/details/84987648
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞