2D Galaxy Shooter: It’s shaping up into a real game!
With the implementation of the power-up system, I can now collect a power-up!
The first power-up is a triple shot. The name says it all. It shoots three lasers for extra firepower for use in sticky situations!
While setting up the power-up, I used Unity’s animation system to animate the triple shot power-up collectible.
To make it work so that the player can pick up the power-up, I created a power-up script and attached it to the triple shot powerup prefab. I want the powerup to detect when the player collided with it. So in the OnTriggerEnter2D()
function, I check to see if the player collided with the powerup. And if it did, I then want to communicate with the player script to have access to a function that activates the triple shot to true.
This function calls TripleShotActive()
in the player script and activates the power-up. It also calls a coroutine that powers down the power-up after five seconds.
public void TripleShotActive()
{
_isTripleShotActive = true; StartCoroutine(TripleShotPowerDownRoutine());
}private IEnumerator TripleShotPowerDownRoutine()
{
yield return new WaitForSeconds(powerDownTime); _isTripleShotActive = false;
}
With everything working in harmony, the game is looking polished as I continue to go through each section of the course.
In the next update, I’ll have a couple of more power-ups!
Thank you for reading. :)