Animating Sprites in Unity

Alberto Garcia
3 min readJan 7, 2023

--

Using sprites in the unity scene feels like importing transparent pieces of plastic paper into a digital environment. They are so versatile as an adapted form of interactive, stop motion film. By simply using a series of PNG files, a worm could eat an entire apple in 4, or 16 bites. Unity provides the Animator component to read the Mecanim animation system; each game object that needs to be animated requires its own animator. An AnimationController runs the animation through the programmed set of values, giving the animator data to alter the current sequence of a game object. This may be manipulated through script, but for this example the Animation Window will suffice.

A square and transparent, mouse-painted canvas

This sprite has “triple shot” as text underneath what looks like an ally space ship. The spacecraft remains green and gray, but the text varies its color through a sequence of 16 files. These files may be used repeatedly and in many different order quite simple. First, select the game object to animate and add an Animator component.

16 PNG files to portray the colors of the rainbow in a looped sequence

The Animation Window is accessible through Window> Animation> Animation. Once opened, select the game object, create a new clip, name that file in reference to the sequence (a second file will be created with the name of the game object, this will be the animator controller); drag the sprite files from the project window into the animation panel. Each sprite will appear throughout the timeline in the selected order as an individual diamond figure. This points may be selected, moved to a different millisecond and duplicated. The purpose of animating this Power Up item is to call the user’s attention and pull the player towards it. Adjust the sprites and their length to achieve this purpose.

If there is no controller, go inside Project> Animations > right-click and create an Animator Controller named in reference to the PowerUp(Triple Shot). This controller file is then dragged to the prefab’s Animator component.

Animation window running the .anim in 1.5 seconds with 20 frames.

The sequences of animation stopped being so linear through video games as the characters and props react to the user’s input. Having so much reusability broadens the possibilities of how game objects come to life in each different moment of the game. Maybe some power ups last two seconds on screen and flash faster while others last five and show fewer colors. It is the same reward, but the different animation tells the user how much time they got to move towards that item before it disappears.

--

--

Alberto Garcia
Alberto Garcia

No responses yet