Enemies shoot powerups
Objective: Allow some enemies to fire laser and destroy powerups.
A new tag, Powerup, is created and all powerup prefabs are tagged with this label. One enemy type, ID 3, targets powerups to destroy them by firing a laser. The code below allows _enemyID 3 to detect and fire at powerups. The local variable hits is an array of RaycastHit2D that stores the output from Physics2D.RaycastAll. Each hit is stepped through using a foreach loop to detect any colliders with a tag of Powerup. If the enemy can fire then an _enemyLaserPrefab is instantiated to destroy the powerup.
The laser script is modified to allow all enemy lasers to destroy powerups if they hit ta Powerup using the OnTriggerEnter2D, see below.
Even powerups are not safe from the enemy assault.