Space Shooter Challenge: Destroying Powerups
Today’s challenge was to have the enemies detect when a powerup is in front of them and then shoot and destroy.
My enemies already fire forwards, so my interpretation of this challenge, was instead to just create logic for any instance of the laser to destroy the powerup, including the player’s own laser.
To create this, I added an else statement to the Powerup’s OnTriggerEnter method. Then, I could use TryGetComponent to return the Laser script if it exists on the object it collided with. If so, the powerup would be destroyed.
Now as a player, you have to be a lot more careful with just firing off shots!