Skip to content

Instantly share code, notes, and snippets.

@elringus
Created June 8, 2017 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elringus/d94cdffe44e8145fe5188e00cce959c1 to your computer and use it in GitHub Desktop.
Save elringus/d94cdffe44e8145fe5188e00cce959c1 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
public class SpriteChanger : MonoBehaviour
{
public List<Sprite> Sprites = new List<Sprite>();
public float ChangeRate = 2f;
private Image image;
private int spriteIndex;
private void Awake ()
{
image = GetComponent<Image>();
}
private void Start ()
{
InvokeRepeating("ChangeSprite", 0, ChangeRate);
}
private void ChangeSprite()
{
if (Sprites.Count == 0) return;
spriteIndex++;
if (spriteIndex >= Sprites.Count)
spriteIndex = 0;
image.sprite = Sprites[spriteIndex];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment