using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; //one sprites public class SpriteAniation : MonoBehaviour { [Header("帧动画的图")] public List sprites=new List(); [Header("播放动画的image")] public Image image; [Header("帧时间,单位毫秒,默认100")] public float Aintime=100f; private int index=0; // Start is called before the first frame update void Start() { if (image==null) { Debug.LogError("image is null"); } if (sprites.Count==0) { Debug.LogError("sprites is not"); } InvokeRepeating("ainstart",0f,(Aintime / 1000)); } void ainstart() { image.overrideSprite = sprites[index]; index++; if (index> sprites.Count-1) { index = 0; } } private void OnDestroy() { sprites = null; } }