Advertisement
Guest User

PlayAnimation

a guest
Dec 15th, 2013
638
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.63 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. [RequireComponent(typeof(SpriteRenderer))]
  6. public class PlayAnimation : MonoBehaviour {
  7.  
  8.     public float playSpeed = 1;
  9.     public List<Sprite> frames;
  10.  
  11.     int currentFrame = 0;
  12.     float timer = 0;
  13.  
  14.     // Use this for initialization
  15.     void Start () {
  16.    
  17.     }
  18.    
  19.     // Update is called once per frame
  20.     void Update () {
  21.         timer += Time.fixedDeltaTime;
  22.  
  23.         if( timer >= playSpeed )
  24.         {
  25.             timer = 0;
  26.             if( currentFrame++ == frames.Count-1)
  27.             {
  28.                 currentFrame = 0;
  29.             }
  30.  
  31.             GetComponent<SpriteRenderer>().sprite = frames[currentFrame];
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement