Last active
August 16, 2017 13:47
-
-
Save buijldert/7f9757b3f3f62baeb1223faf46264d28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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