Objective: Alter the spawn manager to use an array instead of hard coding variable spawns

Now that we have the speed boost powerup finished, lets add it to the list of our spawn manager. We can do this using the array function in Unity, which lets us pre-program a list.

Now in the inspector window we can tell the array list how long we want it to be or how many objects it needs to include. In our case, 3 will be required.

Objective: Create a script that will handle all powerup behaviors in game

Our objective is to create a powerup script that will control all of our powerups instead of having 1 script per variable.

We will achieve this by using a different ID for each variable, which will trigger different parts of our code.

Once we null check the the player, we simply select what which script we need to run based on the ID of our powerup.

Animating in unity is very simple. First select the object we want, then go to window and select animation. Then we will add the animator to the bottom of our screen, next to our game window.

To create an animation, we will click create, create a new folder for animations and save our Tripleshot animation. To create the animation, we will simply click the red record button, then we will drag and drop our sprites in order into the animation window. The animation loops automatically, so we do not need to do anything else.

Our laser now functions as expected, but remains active after the lasers are destroyed, since they are part of a parent object. There is a simple fix to this.

We simply check if the our object has a parent object with a null check. If it does, we destroy everything. If not, we just destroy the laser.

Now that we have the basic code for how the powerup should function, we need to implement its behavior. We will do this by using a similar method to our damage method. In this case, we need a collision to change the state of our variable from false to true. This will make it active for 5 seconds and then switch it back to false, ending our coroutine.

The other part of the code is on the variable itself, which just communicates with the code above upon colliding with the player and preforming a null check.

Marek Ondrej Valco

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store