mitchellvette

Basic Sprite Animator / Unity 3D

Mar 13th, 2012
152
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma strict
  2.  
  3. var frames : int;
  4. var currentFrame : int = 1;
  5. var framesPerSecond : float;
  6. var canAnimate : boolean = true;
  7.  
  8.  
  9. function Update () {
  10.  
  11.         if(canAnimate){
  12.             RunFrameset();
  13.         }
  14. }
  15.  
  16. function RunFrameset(){
  17.     canAnimate = false;
  18.     renderer.material.mainTextureOffset.x += 1.0 / frames;
  19.     currentFrame += 1;
  20.         if(currentFrame > frames){
  21.             renderer.material.mainTextureOffset.x = 0;
  22.             currentFrame = 1;
  23.         }
  24.     var fps : float = 1 / framesPerSecond;
  25.     yield WaitForSeconds(fps);
  26.     canAnimate = true; 
  27. }
RAW Paste Data