Objective: Make it so when the enemy detects a powerup in a certain range in front of it they fire and if they hit destroy the powerup.
Step 1: Create an object to use to detect the powerup (there are other ways to do this, but I find this to work fine here). Using Tag’s to create a new one for powerups. Turn off Mesh renderer as that is not needed.
Step 2: Setup the new object with a box collider 2d trigger and a rigidbody 2d without gravity (doing this will stop the child from triggering the parents collisions.)
Step 3: Create a script for that new object to trigger a method on the parent (in this case we put it on the enemy as a child) to let them know to fire. Make sure to remember to attach it to the new powerup detector object.
Step 4: Have the enemy fire fowards once the powerup is detected.
Step 5: Make the powerup realize it’s been hit by an enemy laser and destroy.
Final: Make sure to add a rigidbody 2d to all the powerups now as well and remember to set their gravity to 0.
Note: You can adjust the detection range by just changing the collider box on the cube object used for Powerup Detector.