Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class GIF_Manager : MonoBehaviour
- {
- //frames
- [SerializeField]
- Sprite[] frames;
- // speed
- [SerializeField]
- float framesPerSecond = 10f;
- void Start()
- {
- object[] loadedIcons = Resources.LoadAll("HeliAttackImage", typeof(Sprite));
- frames = new Sprite[loadedIcons.Length];
- for (int x = 0; x < loadedIcons.Length; x++)
- {
- frames[x] = (Sprite)loadedIcons[x];
- }
- }
- void Update()
- {
- // get index of frame
- int index = (int)(Time.time * framesPerSecond) % frames.Length;
- // check if the Texture array don't equal null
- if (frames[index] != null)
- {
- // get Renderer of this gameobject
- //this.gameObject.GetComponent<Image>().material.mainTexture = frames[index];
- gameObject.GetComponent<Image>().sprite = frames[index];
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment