Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 22nd, 2010 | Syntax: JavaScript | Size: 1.11 KB | Hits: 68 | Expires: Never
Copy text to clipboard
  1.  
  2. var uvAnimationTileX = 1; //Here you can place the number of columns of your sheet.
  3.                            //The above sheet has 24
  4.  
  5. var uvAnimationTileY = 26; //Here you can place the number of rows of your sheet.
  6.                           //The above sheet has 1
  7. var framesPerSecond = 29.0;
  8.  
  9. var myProjector : Projector;
  10.  
  11.  
  12. function Start()
  13. {
  14.        
  15.        
  16. }
  17. function Update () {
  18.  
  19.     // Calculate index
  20.     var index : int = Time.time * framesPerSecond;
  21.     // repeat when exhausting all frames
  22.     index = index % (uvAnimationTileX * uvAnimationTileY);
  23.    
  24.     // Size of every tile
  25.     var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
  26.    
  27.     // split into horizontal and vertical index
  28.     var uIndex = index % uvAnimationTileX;
  29.     var vIndex = index / uvAnimationTileX;
  30.  
  31.     // build offset
  32.     // v coordinate is the bottom of the image in opengl so we need to invert.
  33.     var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
  34.    
  35.    myProjector.material.SetTextureOffset ("_MainTex", offset);
  36.    myProjector.material.SetTextureScale ("_MainTex", size);
  37. }