Player Advantage? Enemies Destroy The Power-Ups! (Part 1)
Enemies and power-ups spawn and are respectively destroyed or collected by the player. But would an enemy really let the player collect a power-up? No! They’d destroy it before that happened!
I’ll add a new variable to the Enemy Gun script:
This will add a small cool-down between shots, so that it isn’t shooting at a power-up every single frame.
I also create a new function inside Enemy Gun:
Now inside the Else, I’ll check if there’s a Power-up in front of this gun, and if there is, shoot the laser:
Add a call to the new function into the existing Update method.
Moving to the Powerup script, I’ll add to it’s OnTriggerEnter2D function:
It should now fire as soon as a Power-Up is detected in front of it:
In Part 2 of this post, I will be making an advanced version that can target any powerup on the screen, as long as it is vertically lower than the enemy!
Up the challenge! Check it out tomorrow!