Real games need items: Triple Shot

Objective: Add game object allowing player to fire three lasers.

Having items that when owned improve the players abilities enhance the play experience by providing both urgency and reward. A powerup is an transient item that provides the player a boost, in this case allowing them to fire three lasers instead of one. Ownership is a boolean variable, _isTripleShotActive, which is false until toggled by the Triple_Shot_Powerup game object. The powerup is sprite art that has an Is Trigger Circle Collider 2D and Rigidbody 2D with zero gravity and a Powerup script.

Powerup game object

The Powerup script moves the powerup down until it moves out of play and is destroyed or collides with the player. If the powerup collides with a player it triggers the Player script using GetComponent<Player>(), calls the ActivateTripleShot() function in the player script and destroys the powerup. To GetComponent, the variable type must match the component name and access it through the transform component.

Powerup script

The Player script contains the private _isTripleShotActive boolean which is accessed using the public ActivateTripleShot() where _isTripleShotActive is set to true and calls a coroutine InactivateTripleShot() to reset _isTripleShotActive to false after 5 seconds. If the coroutine is called from the powerup then the powerup is never destroyed because the coroutine is stopped on destruction of the powerup which started it. So the coroutine must be called from a persistent object, such as the player.

Player script functions

Software engineer