Search Unity

Sprite animation help

Discussion in 'Community Learning & Teaching' started by jason201, May 11, 2013.

  1. jason201

    jason201

    Joined:
    Oct 14, 2011
    Posts:
    123
    So I am wondering how I would implement a sprite sheet with multiple animations on it. Sofar I have this script that just goes from one offset to the other

    Code (csharp):
    1. var uvAnimationTileX = 24; //Here you can place the number of columns of your sheet. //The above sheet has 24
    2.  
    3. var uvAnimationTileY = 1; //Here you can place the number of rows of your sheet. //The above sheet has 1 var framesPerSecond = 10.0;
    4.  
    5. function Update () {
    6.  
    7. // Calculate index
    8. var index : int = Time.time * framesPerSecond;
    9. // repeat when exhausting all frames
    10. index = index % (uvAnimationTileX * uvAnimationTileY);
    11.  
    12. // Size of every tile
    13. var size = Vector2 (1.0 / uvAnimationTileX, 1.0 / uvAnimationTileY);
    14.  
    15. // split into horizontal and vertical index
    16. var uIndex = index % uvAnimationTileX;
    17. var vIndex = index / uvAnimationTileX;
    18.  
    19. // build offset
    20. // v coordinate is the bottom of the image in opengl so we need to invert.
    21. var offset = Vector2 (uIndex * size.x, 1.0 - size.y - vIndex * size.y);
    22.  
    23. renderer.material.SetTextureOffset ("_MainTex", offset);
    24. renderer.material.SetTextureScale ("_MainTex", size);
    25. }
    `
    The problem now is that I would like to make it so that I can have one row be one animation and the next row could be another animation so I could animate a sheet like this

    so I would really appreciate the help if someone would tell me how to do this. Thanks in advance.

    EDIT: I don't have any money to spend on any software
     
  2. Mordekai

    Mordekai

    Joined:
    Nov 8, 2009
    Posts:
    24
  3. VeeBeeMee

    VeeBeeMee

    Joined:
    Apr 21, 2013
    Posts:
    5
    I have used simplesprite, it really is pretty simple :)
     
unityunity