how better create and show animated textures and what better to use (avi, gif, maybe UV moving???)? especially if I need several 2d objects with same animated texture and several with another. And I need to move them in runtime (by mouse, after camera move), change theirs textures.
You’ll need Unity pro to have movie files textured to objects. You can, however create animated textures with image files (sprite sheets) with a bit of code… along the lines of this:
var uvAnimationTileX = 2; //Here you can place the number of columns of your sheet.
//The above sheet has 2
var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet.
//The above sheet has 1
var framesPerSecond = 10.0;
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);
renderer.material.SetTextureOffset ("_MainTex", offset);
renderer.material.SetTextureScale ("_MainTex", size);
}
I grabbed that script from the Unity forums somewhere and worked for me ![]()