Animating Sprites in Unity (2D Space Shooter)

Recently added some animations to the powerups in the 2D Space Shooter project using Unity’s Animator component and a series of sprites. My experience with animating sprites has been fairly limited so far, so I was quite surprised to find how quickly and easily we can do this (assuming the sprites we need are ready to go).

To do this, first open up an Animation tab via Window > Animation > Animation, then select the object in the scene that you want to animate, then click ‘Create’ in the Animation window and create a new .anim file in a location of your choice. To keep things clear and tidy, try saving these in an Animations folder and give them a name ending with ‘_anim’. This will admittedly look quite tautological (e.g. ‘Shield_Powerup_anim.anim’) but in our assets view we won’t see the file type, meaning this’ll let us easily distinguish between our Controllers and the Animations themselves.

Once you’ve done this, make sure you still have the object you want to animate selected and hit the red record button on the Animation window. Then you can select the first sprite you want to use from your assets, hold shift, select the last sprite you want to use, then drag this over into the timeline in the Animation window. Stop recording, and your object should now be able to cycle through these images for an animated effect:

This admittedly a fairly quick and simple way of animating these objects, and in a lot of cases we might want to delve around a bit more in the timeline and Animation Controller to determine when and for how long animations play. But since all we really need at the moment is for this single animation cycle this’ll suit us just fine.

As a quick additional tip: if drag your mouse to draw a marquis over the animation keyframes in the timeline and then release, you should be able to grab the right handle to stretch/draw out this animation so that it runs and cycles slower. Totally depends on the effect you want to go for of course, but just thought I’d mention that in case you’d like to slow the animation down 😉

Game Developer | Game Design and Literature Graduate