My 90 day journey becoming a Unity game developer: Day-13
Objective: We will create a Triple Shot prefab that will be used to defeat enemies when the player grabs a special powerup for a limited amount of time. This is the final result of activating the Triple Shot.
Let’s begin with dragging the Laser Prefab into the Hierarchy. Make sure the laser’s transform position is set to 0 on each axis. Move the laser up in the Y-axis to show the laser in front of the ship’s gun area. Press CTRL-D to duplicate another laser, and drag it into the position where the laser will be shot from on either the left or right side of the ship. When that laser is set in its position, duplicate one more laser and go over to the X-axis position of its Transform. If the second laser position has a negative sign in front of its value, delete the negative sign from the value without changing the numbers. If not, add a negative sign in front of the X-axis numbers.
Open the Player script, create a new variable bool name isTripleShotActive and set it to false. Also, create a new variable GameObject name tripleShotPrefab. Head over to the FireLaser() method, create an if() condition that checks to see if the triple shot is active. If so, we will instantiate the tripleShotPrefab from the player’s position, and if not we will shoot a regular laser.
Delete the Triple Shot Prefab from the Hierarchy, click on the Player, and drag it over to the tripleShotPrefab variable on the Player’s script component. When we play the game, activate the triple shot by clicking on the isTripleShotActive box.
Next time we will work on the Triple Shot’s behavior. Until then …