_EagleOwle_

GIF_Manager

Feb 19th, 2020
126
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class GIF_Manager : MonoBehaviour
  7. {
  8.     //frames
  9.     [SerializeField]
  10.     Sprite[] frames;
  11.  
  12.     // speed
  13.     [SerializeField]
  14.     float framesPerSecond = 10f;
  15.  
  16.     void Start()
  17.     {
  18.         object[] loadedIcons = Resources.LoadAll("HeliAttackImage", typeof(Sprite));
  19.  
  20.         frames = new Sprite[loadedIcons.Length];
  21.  
  22.         for (int x = 0; x < loadedIcons.Length; x++)
  23.         {
  24.             frames[x] = (Sprite)loadedIcons[x];
  25.         }
  26.     }
  27.  
  28.     void Update()
  29.     {
  30.         // get index of frame
  31.         int index = (int)(Time.time * framesPerSecond) % frames.Length;
  32.         // check if the Texture array don't equal null
  33.         if (frames[index] != null)
  34.         {
  35.             // get Renderer of this gameobject
  36.             //this.gameObject.GetComponent<Image>().material.mainTexture = frames[index];
  37.             gameObject.GetComponent<Image>().sprite = frames[index];
  38.         }
  39.     }
  40. }
RAW Paste Data