Unity Animation顺序播放动画

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/qq_39097425/article/details/84987648

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

        }
    }
}

 

展开阅读全文

没有更多推荐了,返回首页