using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class AnimatedImage : MonoBehaviour {

    [SerializeField] private Sprite[] _images;
    [SerializeField] private float _frameLen;
    private int _frameN;
    private float _time;

    protected void Update() {
        _time -= Time.deltaTime;
        if (_time <= 0) {
            _time += _frameLen;
            NextFrame();
        }
    }

    private void NextFrame() {
        _frameN = (_frameN + 1) % _images.Length;
        GetComponent<Image>().sprite = _images[_frameN];
    }

}
