Skip to content

Instantly share code, notes, and snippets.

@buijldert
Last active August 16, 2017 13:47
Show Gist options
  • Save buijldert/7f9757b3f3f62baeb1223faf46264d28 to your computer and use it in GitHub Desktop.
Save buijldert/7f9757b3f3f62baeb1223faf46264d28 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ImageAnimation : MonoBehaviour
{
[SerializeField]
private Image _animatedImage;
[SerializeField]
private float _animationDuration;
private float _animationFrames;
private float _spriteSwapDelay;
private void Animate(List<Sprite> animationSprites)
{
_animationFrames = animationSprites.Count;
_spriteSwapDelay = _animationDuration / _animationFrames;
StartCoroutine(AnimateImage(animationSprites));
}
private IEnumerator AnimateImage(List<Sprite> animationSprites)
{
for (int i = 0; i < animationSprites.Count; i++)
{
_animatedImage.sprite = animationSprites[i];
yield return new WaitForSeconds(_spriteSwapDelay);
}
StartCoroutine(AnimateCard(animationSprites));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment