You want to work in this business? You gotta be thirsty!
All joking aside, having your game object art animated came make a dull game come alive. If the assets you are using have the sprites for each frame of the animation already cut into individual images, then the process can be as simple as drag and drop. Literally. (I will cover slicing up a sprite sheet into individual frames/images in an upcoming article.)
You can add the animation to an already existing game object by selecting the game object then opening the Animation window and selecting ‘Create’ OR you can just select all of the images (frames) for the animation and drag them into the Hierarchy window. Unity will create the game object and the animation for you. I highly recommend saving the anim file into a folder just for animations. Keeping your project assets neatly arranged in folders can save your sanity.
Once the game object is created and the animation and animator controller are created, you can adjust the settings to get the animation speed just as you want it. For the shield power-up, I like the slightly slower animation.
The animation is set to loop (or to continuously play) by default and we do want it to work that way for this power-up. If you do not want an animation ) to loop automatically, enemy ship explosions only need to play once for example, then you can turn that option off by selecting the animation in the Project view and toggling the Loop Time setting.
And now we have animated power-ups!
Here, frozen in place, is how they will look during actual game play. Spawned randomly from the Spawn Manager we created in an earlier article, and after a randomly selected time delay, each will fly down the screen and the player can collect and use them.
The game is starting to take shape. There is still some work to do to get the functionality of all these power-ups working correctly.
However, some planning needs to be done as well. How long should these power-ups last? How often should they spawn? You know, life’s important questions that everyone wants the answers to.
Also, I’d like to be able to easily add more in future updates of the game so I need to plan out a way to make the power-up system modular and able to handle multiple types without having to create the behaviors for each from scratch.
One step at a time however. Tomorrow’s article will cover how to determine how long power-ups should last. It is a delicate balance between helping the player play longer but not making the game too easy.
See you there!