Unity Guide

Animating sprites in Unity

A quick guide about how to animate sprites in Unity

Fernando Alcantara Santana
Nerd For Tech

--

Objective: Animate a power-up item in Unity for a space shooter game.

Now that we have implemented a power-up item in Unity for the space shooter game, we need to highlight it to make it easier to be noticed by the player. In order to do it, let’s animate the sprite using the tools of the Unity Editor.

First, we need to select the power-up item that will be animated in the scene:

Then, select Window > Animation > Animation and a new window will be prompted. We can drag it in the layout as we like:

In this new Animation view we’ll be able to animate the sprite of the power-up item.

Before creating the animation create a new folder to store the animations and keep the assets organized. Then, click on the create button and give a name to the new animation:

Once we created the animation file, let’s start recording the animation of the sprite by clicking in the red light, which will enable the recording per keyframe:

Then, select the different sprites that will give shape to the animation per frame and drag them to the Dopesheet. If the sprites of the animation are in order they’ll accommodate automatically:

Once the keyframes are in order, stop the recording by clicking the red light again.

To verify that the animation works, select the power-up item in the scene view and click on the play button to view the animation clip:

Also, if you select the power-up item in the scene, you’ll notice that there’s a new Animator component that includes the animation controller of the animation created before:

If you double-click the controller, a new Animator window will be prompted and it will show how the animation clip is handled when the application is running:

If we run the game in the Unity editor, we’ll see that the animation is working and it loops:

So, if we don’t want the animation to loop when the game is running, we need to disable the Loop Time option that the animation clip displays in the inspector:

In this case, I want the animation to be in a loop.

Now when the game is running, we’ll be able to see the animation of the power-up item every time it spawns in the scene:

And that’s it, you can animate a sprite in Unity! :D. I’ll see you in the next post, where I’ll be showing how to create modular power-up systems for the space shooter game.

If you want to know more about me, feel free to connect with me on LinkedIn or visit my website :D

--

--

Fernando Alcantara Santana
Nerd For Tech

A passionate computer technology engineer and Unity developer that is always looking to grow in every aspect of life :).