Animating Sprites in Unity

Day 18- Making 2D Space Shooter Game

Animations are the major part of game development and it is one of the element that gives life to your game. You can make a game without an animation but it will be lifeless and mostly non-enjoyable.

So how do we make an animation in a 2D game? To make an animation, you first need to have a set of sprites that represents certain frame of your animation.

Sprites are simple 2D objects that have graphical images (called textures) on them. Unity uses sprites by default when the engine is in 2D mode.

This is a simple example of a sprite. To use it in your game, you should note that the Texture type should be Sprite (2D and UI).

Here is a simple example of a sprite created to represent a frame in the animation. As you can see the text it highlighted in different colors and the ship is brightened and darkened.

To create an animation, you first need a gameobject that you are going to animate. Here, I took first frame as my gameobject(index image) then while selecting that gameobject, go to Windows->Animation->Animation. After you have opened the animation panel, while selecting the gameobject select create. It will take you to your file explorer, It is advised that you create a Animation folder and inside that you give a descriptive name to your animation and end the name with anim for future easy navigation. ex: Tripleshot_anim, Shield_anim, etc.

After you have saved the animation, press the red recording button and you can now drag your animation sprite inside the animation panel. You can then check your animation in the scene view by pressing play button in the animation panel.

Press the red recording button again to stop recording and now your animation is successfully created. you can check the Animator to play the animation during runtime.

Now lets say you want your animation to play only once while unity plays it in loop by default. You can disable the loop by selecting the animation and disabling the loop time.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store