12345678910111213141516171819202122232425262728293031 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class SpriteAnimation : MonoBehaviour
- {
- public float speed = 0.5f;
- public List<Sprite> sprites;
- public Image img;
- private int index = 0;
- private float timer = 0;
- void Update()
- {
- index %= sprites.Count;
- img.sprite = sprites[index];
- timer += Time.deltaTime * 0.1f;
- if(timer >= speed)
- {
- index++;
- timer = 0;
- }
- }
- }
|