Created
June 8, 2017 18:17
-
-
Save elringus/d94cdffe44e8145fe5188e00cce959c1 to your computer and use it in GitHub Desktop.
This file contains 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 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