Advertisement
kosukito

Untitled

Mar 25th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.13 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5.  
  6. [System.Serializable]
  7. public class Animacion
  8. {
  9.     public string animationName;
  10.     public float animationDuration;
  11.     public Frame[] frames;
  12.  
  13.     public Animacion(string _name, float _duration)
  14.     {
  15.         animationName = _name;
  16.         animationDuration = _duration;
  17.     }
  18. }
  19.  
  20. [System.Serializable]
  21. public class Frame
  22. {
  23.     [Range(0.0f,1.0f)]
  24.     public float frameDuration;
  25.     public Sprite sprite;
  26. }
  27.  
  28. namespace LostPolygon.SwiftShadows
  29. {
  30.     public class ShadowAnimator : MonoBehaviour
  31.     {
  32.         public SwiftShadow swiftShadowScript;
  33.         public string animationToPlay;
  34.         public Animacion[] animationsSetup;
  35.  
  36.         private Sprite spriteNew;
  37.         private Frame[] animToPlay;
  38.         private float timeLeft = 2.0f;
  39.  
  40.         // Use this for initialization
  41.         void Start()
  42.         {
  43.             spriteNew = animationsSetup[0].frames[0].sprite;
  44.  
  45.             for (int i = 0; i < animationsSetup.Length; i++)
  46.             {
  47.                 if (animationsSetup[i].animationName == animationToPlay)
  48.                 {
  49.                     animToPlay = animationsSetup[i].frames;
  50.                 }
  51.             }
  52.         }
  53.  
  54.         // Update is called once per frame
  55.         void Update()
  56.         {
  57.             timeLeft -= Time.deltaTime;
  58.  
  59.             if (timeLeft <= 0)
  60.             {
  61.                 swiftShadowScript._sprite = spriteNew; // change the sprite
  62.                 swiftShadowScript.UpdateTextureUV();   // update SwiftShadow
  63.  
  64.                 StartCoroutine(changeSprite());
  65.                 Debug.Log(timeLeft + "LA PIJA");
  66.                 timeLeft = 2f;
  67.             }
  68.         }
  69.  
  70.         IEnumerator changeSprite()
  71.         {
  72.             for (int i = 0; i < animToPlay.Length; i++)
  73.             {
  74.                 spriteNew = animToPlay[i].sprite;
  75.  
  76.                 yield return new WaitForSeconds(2f);
  77.  
  78.                 Debug.Log(i);
  79.                 Debug.Log(animToPlay[i].sprite.name);
  80.  
  81.                 if (i > animToPlay.Length) { i = 0; }
  82.             }
  83.  
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement