Making sprinkles
In the Prefabs section, we created the Prefab for our sprinkle projectile. In this section, we will see how to make sprinkles move into the 2D space. In particular, we will learn how to create and use scripts in Unity for 2D game elements.
The projectile class
Since there might be different projectiles in our game that can be thrown against the sweet-tooth pandas, and not only sprinkles, we need to define a general class. All the different kinds of projectile will follow some general rules:
They move in a straight line
They carry information about how much damage they will inflict on the enemies
Whereas the first is identical for all the projectiles, the second depends on the specific kind of projectile that will be fired. So, we need to create a template. Once we attach this script to a game object, we can set some of its variables and tweak its behavior. In this specific case, we want to tweak how much damage is given and how fast.
Scripting the projectile mother class
So, to...