Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //****** Donations are greatly appreciated. ******
- //****** You can donate directly to Jesse through paypal at https://www.paypal.me/JEtzler ******
- var uvAnimationTileX = 4;
- var uvAnimationTileY = 4;
- var framesPerSecond = 10.0;
- function Update () {
- // Calculate index
- var index : int = Time.time * framesPerSecond;
- // repeat when exhausting all frames
- index = index % (3 * 1);
- // 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);
- renderer.material.SetTextureOffset ("_MainTex", offset);
- renderer.material.SetTextureScale ("_MainTex", size);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement