Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- [System.Serializable]
- public class Animacion
- {
- public string animationName;
- public float animationDuration;
- public Frame[] frames;
- public Animacion(string _name, float _duration)
- {
- animationName = _name;
- animationDuration = _duration;
- }
- }
- [System.Serializable]
- public class Frame
- {
- [Range(0.0f,1.0f)]
- public float frameDuration;
- public Sprite sprite;
- }
- namespace LostPolygon.SwiftShadows
- {
- public class ShadowAnimator : MonoBehaviour
- {
- public SwiftShadow swiftShadowScript;
- public string animationToPlay;
- public Animacion[] animationsSetup;
- private Sprite spriteNew;
- private Frame[] animToPlay;
- private float timeLeft = 2.0f;
- // Use this for initialization
- void Start()
- {
- spriteNew = animationsSetup[0].frames[0].sprite;
- for (int i = 0; i < animationsSetup.Length; i++)
- {
- if (animationsSetup[i].animationName == animationToPlay)
- {
- animToPlay = animationsSetup[i].frames;
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- timeLeft -= Time.deltaTime;
- if (timeLeft <= 0)
- {
- swiftShadowScript._sprite = spriteNew; // change the sprite
- swiftShadowScript.UpdateTextureUV(); // update SwiftShadow
- StartCoroutine(changeSprite());
- Debug.Log(timeLeft + "LA PIJA");
- timeLeft = 2f;
- }
- }
- IEnumerator changeSprite()
- {
- for (int i = 0; i < animToPlay.Length; i++)
- {
- spriteNew = animToPlay[i].sprite;
- yield return new WaitForSeconds(2f);
- Debug.Log(i);
- Debug.Log(animToPlay[i].sprite.name);
- if (i > animToPlay.Length) { i = 0; }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement