Starting To Feel Like A Real Video Game
We are done with our prototype. Things are finally starting to come together. We’ve added a nice space background, and some high fidelity graphics. It is starting to remind me of the games of my childhood. We have come a long way from day one.
But, We’re not done yet! Things are starting to get exciting. It’s time to beef up our game with some bonus features. The first thing we’ll be doing is adding a triple shot powerup to the game. There are two parts to the powerup that we need to focus on. one is the functionality of firing three lasers. The other is the actual object that we collect to activate the powerup. Let’s start by creating the three lasers.
Drag the Laser prefab into the Hierarchy. duplicate the prefab and place the other two objects at their desired location. the Y-axis values for the two duplicates should be the same. and the X-axis values should be opposite. For example, if the left laser x-axis is -0.77 then the right laser will be set at +0.77. This ensures that the positioning for all three lasers will be correct.
Next, create an empty game object and name it Triple_Shot. Highlight all three laser objects in the Hierarchy and drag them into the Triple_Shot object. This creates a Parent object with three child objects.
To make the triple shot a prefab, just drag it into the Prefabs folder. It should turn blue if done successfully. Now that we have the prefab, we can delete it from the Hierarchy tab.
Now, in our code, we can begin developing logic to instantiate the triple shot if we collect the triple shot power up.
Now we move to the player script. We need to tell that player that it will pick up a triple shot sprite, and enable the triple shot power up. After five seconds, we disable the triple shot.
We’ll need a Boolean variable to check if the power up is active and also a game object variable for the prefab(In Yellow). We use the Serialize Field so that we can see the variables in the inspector. isTripleShotActive is initially set to false because the triple shot power up is not always on.
Later, we will create the logic to activate the triple shot. For now, we can activate it from the inspector tab. Don’t forget to drag the triple shot prefab into the reference box in the player script component, it won’t work without that reference.
When the triple shot power up is active( ==true), we will instantiate the triple shot prefab. Otherwise we instantiate the laser.
If your ran your program at this point, you might notice that the laser is a little off.
Select the Player object in the Hierarchy and ensure the transform position is zero for all three axis.
If you haven’t already, drag the triple shot prefab into the Hierarchy tab. select the Triple Shot object and set it’s position to zero, to match the player. Next Select each one of the child lasers in the triple shot and adjust their position. You can use the Scene view for visual reference.
When you have all three lasers positioned correctly, go back and select the parent object (Triple Shot) again. In the Inspector tab, select the overrides box and click on apply all.
Run the program and check for proper alignment. If everything is good, you can delete the triple shot object from the Hierarchy tab.