- Home /
Playing UV-Animation on a Plane, without particle system?
Want to make a explosion on ONE plane with UV-Animations!
I have tried the particle renderer, which can add UV-Animations ON a particel system. But what i need is a simple plane, which will be added via script, with an UV-Animation (tiled based explosion) on it.
Using a imported Plane with a particle renderer on it, wont work! Using the particle system, brings the particle plane, which is reduced to 1, to popup and vanish somehow around the enviroment. beside the fact i dont want to use particle system. just need a simple plane with uv-animations on it, which will be added via script and a lifetime.
O_O ....thnx for any help!
Answer by duck · Apr 22, 2010 at 11:01 AM
I once used this little snippet to animate the UVs of my plane, for a similar purpose:
This was for an 8x8 grid. The 'padding' value determines how much inside the border of each grid cell is actually sampled - to avoid 'bleeding' between animation frames.
It returns a list of two Vector2s. The first is the lower-left corner of the animation frame, the second contains the width and height of the animation frame in UV units.
Vector2[] GetSpriteUVs(int frameNum) { int gridSize = 8; float padding = 0.1f;
int x = frameNum % gridSize;
int y = (gridSize-1) - (frameNum / gridSize);
float u = (float)x / (float)gridSize;
float v = (float)y / (float)gridSize;
u += (1.0f / (float)gridSize) * padding;
v += (1.0f / (float)gridSize) * padding;
float w = (1.0f / (float)gridSize) * (1 - padding * 2);
float h = (1.0f / (float)gridSize) * (1 - padding * 2);
Vector2[] uvs = new Vector2[] { new Vector2(u,v), new Vector2(w,h) };
return uvs;
}
Another option would be to take a look at the SpriteManager script on the Wiki, which has this functionality built-in.
Did this solve your problem? (if so, remember to click the 'accept' tick icon, and vote up the answer)