Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ImageFlipAnimation : MonoBehaviour
- {
- [SerializeField] Sprite[] sprites;
- [SerializeField] Image image;
- [SerializeField] float fps = 10;
- public void Play()
- {
- Stop();
- StartCoroutine(AnimSequence());
- }
- public void Stop()
- {
- StopAllCoroutines();
- ShowFrame(0);
- }
- IEnumerator AnimSequence()
- {
- var delay = new WaitForSeconds(1 / fps);
- int index = 0;
- while(true)
- {
- if (index >= sprites.Length) index = 0;
- ShowFrame(index);
- index++;
- yield return delay;
- }
- }
- void ShowFrame(int index)
- {
- image.sprite = sprites[index];
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement