Animating Sprites in Unity
Animations are the cornerstone of game development.
One of the easiest ways to bring your game to life is by animating your sprites!
If you are fortunate enough to have a sequence of sprites available, you can start by dragging the first image in the sequence into the hierarchy:
While the new gameobject is selected in the hierarchy, make sure your Animation window is open and select the “Create” button, and name your animation:
From here, it’s just a matter of selecting the sprite sequence and dragging them into your new animation window:
You can see that Unity automatically converted all of the separate sprites into keyframes which can be previewed by selecting the play button from within the Animation window.
This is extremely easy but what about times when you don’t have separate sprites?
Unity has a vast array of tools that are at your disposal for sprite animations!
I won’t go into all of them here but one of the more common animations you can make are from sprite sheets.
Sprite sheets have a sequence mapped out in a single image like this:
Unity has the ability to automatically separate these after you install “2D Sprite” from the package manager:
There are a few settings that need to be changed in order to edit the sprite. The Texture Type has to be set as a “Sprite” and the Sprite Mode set to “Multiple”:
After you have applied the changes, you can select the “Sprite Editor” button which will bring up the sprite editor window. Within the Sprite Editor, you have options as to how you want your images divided. Here I’m selecting “Automatic” and then clicking on “Apply”
Now you can follow the steps from above…drag an image into the hierarchy, then select the frames you want and create your animation:
By default, Unity runs it’s animations at 60 fps but you can adjust that to suit your needs like I did here by dropping it to 15 fps