How to animate a texture

Hey, I’m pretty much new to Unity and I’m using the free version.

I have made a series of about 40 pictures of water moving. For example:

alt text
20966-frame_0002.png

(Not sure if they’re the best examples out of the lot)

Now, I’ve got my plane and I’ve found a script online (unity community)

#pragma strict

var uvAnimationTileX = 24; //Here you can place the number of columns of your sheet. 
                           //The above sheet has 24
 
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);
}

Now to my question, how can I turn these PNG’s into one animation and put it onto my water plane so I can get realistic looking water without using the pro feature.

Sorry for the length question,

Thanks in advance,
CMNatic

That code is (I think) for animating a spritesheet. That’s a standard trick, invented long before Unity. You can look up examples and how to make and use them anywhere. Then, those top two lines about TileX and TileY should make complete sense, including what you need to change them to.

Like Owen said, it’s spritesheet animation. Basically rough steps would be:

  • Combine all images and make spritesheet x by y
  • Assign spritesheet texture to object you want to use
  • Offset texture by x amount and by y amount

For example you have 40 images you can make spritesheet 6x7 last row will have only 4 images.
Since Unity UV goes from 0 to 1 your X offset will be 1/6=0.166 and Y offset 1/7= 0.142
So now you just offset by .166 till the last image then increment Y offset by .142 and call this routine X times per second.

Here is simple example in Documentation