Road to Game Dev: Animating Sprites in Unity

Rowan Mcmanus
3 min readJul 11, 2021

One of the great secrets to making games look pretty is in the animations. Even a little bit of animation can go a long, long way. Let’s take a look at how Unity lets you animate sprites, and even directly control them!

The Animation Tool

Above, you see the animation tool. In order to create an animation, you need to start by selecting the thing you’d like to animate. In this case, I’m animating the shield powerup prefab. From there, open the animation panel, and “create” a new animation, saving the file somewhere you can recognize. Simply dragging and dropping the files in puts them on the timeline and starts the animation. You can use the top of the timeline to adjust timing, as well as a myriad of other options. You may also notice that this creates an “Animator Controller” file as well….

The Animator

The animator is where you can actually control your animations in code. This gets especially handy if you have multiple different animations, or simply want to pause an animation. For example, we have a lovely enemy explosion:

Did you know the first frame of this is actually what we’re using for the enemies normally? But, we don’t want enemies to just constantly be exploding — that’s where the controller comes in. Each “State” represents a different type of animation, or you can have “empty” states where nothing is moving. Then you can create transitions to move between states when certain conditions, called “Parameters”, are met. If we select that transition from “Empty” to the destruction animation, here’s what we see:

We’ve created a “Trigger” parameter called onEnemyDeath, and call the transition when that gets triggered. Of note, we’ve also disabled “Has Exit Time”; with that enabled, the animation can “stick” on the empty state before actually starting up. Not very good for an explosion. The real question is: How do we access any of these through code?

Yep, it really is that easy. Just find the Animator component, then use the in-built “SetTrigger” function to change the state of that trigger. Last thing to do is make sure it’s set not to loop. These fundamentals should be enough to equip you with the tools for a huge variety of animations and controls. Coming up next, we’ll be exploring even more of Unity’s tools to use!

--

--