Search Unity

Animating Mesh with UV's?

Discussion in 'Scripting' started by stulleman, Oct 22, 2014.

  1. stulleman

    stulleman

    Joined:
    Jun 5, 2013
    Posts:
    44
    Hey Guys,

    I have a little problem while trying to animate my meshes.
    I have a 2d sidescroller type of game which generates chunks of terrain on the fly.
    I have a big Array of byte data representing the type of blocks in each chunk.
    But some of those blocks should be animated. Like the flames of a torch for example.
    So I thought about this:
    • loop through each block in this chunk
    • see if it's an animated block
    • if so, set uv Coordinates to next animation image (here I have some problems)
    • First I rebuilt the entire mesh, now I just update the uv's
    First of all, is this the way to approach this?
    If yes, how would you go about storing the current animation index?
    Would you make an array (same size of world Array) to store the current Animation index for each block?

    And a little bit Off Topic but still fits:

    If you let's say have a chest in your game. Would you make it a part of the mesh, or use a Prefab with a SpriteRenderer on it? My Problem with this solution is that I don't have any reference to it from the script. If I want to delete a block I just have to set the value in the Array to 0. With Prefabs it's kind of complicated.

    Hope someone can help or suggest something!