Untitled
By: a guest | Mar 22nd, 2010 | Syntax:
JavaScript | Size: 1.11 KB | Hits: 68 | Expires: Never
var uvAnimationTileX = 1; //Here you can place the number of columns of your sheet.
//The above sheet has 24
var uvAnimationTileY = 26; //Here you can place the number of rows of your sheet.
//The above sheet has 1
var framesPerSecond = 29.0;
var myProjector : Projector;
function Start()
{
}
function Update () {
// Calculate index
var index : int = Time.time * framesPerSecond;
// repeat when exhausting all frames
index = index % (uvAnimationTileX * uvAnimationTileY);
// Size of every tile
var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
// split into horizontal and vertical index
var uIndex = index % uvAnimationTileX;
var vIndex = index / uvAnimationTileX;
// build offset
// v coordinate is the bottom of the image in opengl so we need to invert.
var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
myProjector.material.SetTextureOffset ("_MainTex", offset);
myProjector.material.SetTextureScale ("_MainTex", size);
}