Animating Sprites in Unity

by Lance Gold

A 2D gameObject is a Sprite

Return to index

An Animation is a display of several related Sprites one at a time. This example animates a Triple Shot sprite with different font colors appearing.

Highlight the desired object in the hierarchy.

Highlight Triple_Shot_Powerup

Highlight Triple_Shot_Powerup

From the Window menu, select Animation — Animation

Highlight, select from the Window menu

Highlight, select from the Window menu

Unity pops up an Animation Window, which can be docked next to the Console and Game tabs. (or not, for wide screen developers)

Dock the Animation pane with the Console and Game panes

Dock the Animation pane with the Console and Game panes

Click “Create”

Create new Animator and Animation

Create new Animator and Animation

Create a new folder in the project assets to file animations

Create New folder to organize animation assets

Create New folder to organize animation assets

When naming saving the animation asset, use ‘_’ underscores.

New animation file name

New animation file name

This is an animation dopesheet:

Animation dopesheet

Animation dopesheet

Here is the animation process:

(a) press red record button to start recording (0:00–0:something timer changes color).

(b) drag and drop images to the sheet below the 0:00 — 0:something timer, also drag multiple images.

Press Record and drag images

Press Record and drag images

After the image(s) drop, the detail appears on the timeline.

Image detail on timeline

Image detail on timeline

Press the record button a second time to end recording. Now the Dopesheet rewind, play, and step frame by frame control buttons can be used to review the animation.

Dopesheet with frame by frame, play and rewind buttons

Dopesheet with frame by frame, play and rewind buttons

The animation now appears in the assets pane with its “Triple_Shot_powerup” controller.

Animation listed in Assets

Animation listed in Assets

Highlighting the GameObject shows the Animator as an additional component with the “Triple_Shot_Powerup” added as “Controller”

Inspector for GameObject listing new Animation component

Inspector for GameObject listing new Animation component

Double clicking the animation in the Assets, or clicking “Open” in the Inspector opens the Animation controller pane.

Animation in Inspector with Open button

Animation in Inspector with Open button

The controller pane maps out the animation. After “Entry”, the orange animation loops.

Animation controller with map

Animation controller with map

Testing the Animation

To view the animation of the gameObject without the object moving around on the screen, highlight the Prefabs object and set the variable [Serialized] _speed to zero.

Prefab object’s variable Speed set to zero

Prefab object’s variable Speed set to zero

Animation looping is a Unity default. There is a check box to stop looping. Highlight the animation in the Assets pane and uncheck the box in the Inspector. Animation Loop Time check box in Inspector

Animation Loop Time check box in Inspector