Nerd For Tech
Published in

Nerd For Tech

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!

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store