My journey becoming a Unity game developer: Animating Sprites in Unity. Setting up the Triple Shot Powerup to animate when active onscreen.
Objective: Making the Triple Shot Powerup game object animate. Using the powerup sprite animation sheet in Unity’s Animation window to setup the Triple Shot Powerup’s animation in the game.
With the Triple Shot Powerup we have a collection of sprites that can animate during gameplay. To use these sprites in the game we need to use Unity’s Animation window. There are 2 ways to open the Animation window with the 1st way is to go up to Window->Animation->Animation.
The 2nd way to open the Animation window is by going to your Triple Shot Powerup sprites in the Sprites folder. Then right-click on one sprite and select Create->Animation. Make sure to dock the Animation window tab next to the Game tab below the Scene tab so we can have access to both tabs.
Next, click on the Create button which will ask us for the location where we want our new animations stored. Create a new folder name Animations to hold these new animations inside of your Game’s folder under Assets. Name this Triple Shot Powerup animation TripleShotPowerUp_anim. We add “_anim” after the name of the animation just to differentiate this name from other game objects with the same name such as TripleShotPowerUp prefab.
Inside the Sprites folder, drag all the Triple Shot PowerUp animation sprites into the Animation Timeline. When we press the play, notice the sprites animating in our Scene view.
With our Triple Shot PowerUp animation created there are a couple of things we need to be aware of. The 1st thing is that when we create a new animation, a new component name Animator will be created also. The Animator uses an Animator Controller to arrange and manage a set of Animation Clips. It uses Animation Transitions between clips to go from one animation clip to another where we can switch between them when certain game conditions occur using a State Machine. State Machine is like a flow-chart of Animation Clips and Transitions that allows us to control the speed, transition, and duration of the clips. For example, we can switch from a Walk Animation Clip to a Jump Animation Clip whenever the spacebar is pressed. Even if we have only a single Animation Clip to use, we still need to use it in the Animator for our game object or character.
The 2nd thing we can look at is the TripleShotPowerUp_anim clip inside the Animations folder under the Assets folder. There we can turn Loop Time ON if we want the animation playing repeatedly, or OFF if we just want the animation to play one time only.
On the Triple Shot PowerUp object, we set the speed to zero under the PowerUps script component to keep the powerup from moving down the screen. Play the game to see the animation sprites playing. When we go into the Animator tab while the game is playing, notice the blue bar moving inside the TripleShotPowerUp_anim state machine. This gives us indication that this animation state is actively playing at the moment.
One last thing we will look at is the Animation Timeline. If we wanted to change the animation from playing at 60 frames per second, change the Samples rate from 60 to another number that you’re more satisfied with. In this demonstration we used 25 frames per second and 10 frames per second to see their results.
Also, we can space the animation keys further apart from each other by left-click and select all keyframes after the keyframe we don’t want to change. Then, left-click hold and drag the selected keyframes to a new position on the timeline. We can do this with other keyframes to change the pattern in which the animation will play.
Make sure to select the Triple Shot PowerUp game object in the Hierarchy, and select the Overrides drop-down list to see if any overrides need to be made. If so, choose Apply All to apply all the changes made to the Triple Shot PowerUp game object to the prefab object.