Allowing the enemy to destroy powerups.

In today’s article, we will give the enemy the ability to shoot and destroy powerups. To start this, we will open our ‘Enemy’ script and create a couple of new variables.

We’re going to create a new function called ‘ShootPowerups’ and create a raycast. We’re going to set it to look for the layer name ‘Powerup’. If the ray hits the powerup item with the ‘Powerup’ layer on it, then it will shoot at the powerup.

We will call this function in ‘Update’. Also, you will need to create a new layer name of ‘Powerup’ and give that layer to all the powerups that you want to have the ability to be destroyed.