Creating a 2D animation with Unity
Published: 2019-11-08 04:17:12

Unity makes creating animations very easy with a simple drag and drop method. To create a 2D animation in Unity, you first need some art assets that has each frames of a movement. There are many assets online for free. You can even find some on [Unity Asset Store](https://assetstore.unity.com/) or [itch.io](https://itch.io/game-assets). For this project, I will be using the 1bit pack from [Kenney's assets](https://www.kenney.nl/assets). If your sprite sheet came with more things attached to it than you need, you can go ahead and crop out the image file as an easy fix so that there are only the sprite items we are going to use. The sprites that I am using looks like this:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/brj1itb8qi2doyz2j7m0.png)

Once you have the sprite sheets ready, import it into Unity and click on the image file. The inspector tab should be open to that selected image file. In the inspector tab, go to `Sprite Mode`. The default settings should be `Single`. Click the drop down menu and change that to `Multiple` so that the image is splitting each section into multiple items. This means that the image is no longer holding one item but many so that it can loop over each item to play the animation. Click `Apply` at the bottom and then `Sprite Editor` below `Sprite Mode`.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/z1tata97m1xcluatfnyv.png)
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/z4l2e5mnhrspdjazus39.png)

When the Sprite Editor is open, slice the image. Each item should then be clickable and customizable. The slice should be a prompt at the top of the window that looks something like this:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/fw7zqhkpja8d83xusp89.png)

After you close the sprite editor, grab the sprite and simply place it in the Scene tab. You could also create a new animation through the Animation This should prompt a new window that asks you to create a new animation.
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/65kjyu0dfv96cv0rpsq6.png)
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/wrbsu0bd9dmh2kx9rz2z.png) 
And that's all! Hit the play button and see your sprite animation. If you take a look at the inspector tab, you should be able to see `Sprite` in Sprite Renderer changing. You can further edit the animations in the inspector tab, too. Since the sprites that I used were very small I had to expand the size so the final product looks a bit blurry. The final animation for this project looks like this:
![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/ajz2884l6fj0k3db9jhe.gif)

Note that this is only a simple cover of animation in Unity and does not go over player movement animation. If you want to create movement animation, you could create an animation and attach it to the object as a component along with some changes in code depending on how you want to animate your objects in your c# script files of your object. To learn more about animating in Unity, there is more information in [Unity's documentations](https://docs.unity3d.com/Manual/Unity2D.html) and Unity also offers a lot of tutorials in [Unity Learn](https://learn.unity.com/)