Add enemies that can destroy pickups

The next requirement is to get the enemy to destroy pickups if these are in front of them. Just like detecting the player in the previous articles, we will need to detect the Power ups too.

To damage the Power up, we need to add tag to the Powerup so the laser can determine if it hit it or not.

On Enemy’s OnTriggerEnter2D method, it detects if there’s a Collider with a PowerupPresence tag and if it can fire, shoot it down:

On the Laser’s OnTriggerEntry2D, destroy the Power up if the collider tag is Powerup.

Now, the enemy can destroy power ups.