Make Enemies Able to Destroy the Pickups in Unity

Adding more annoying stuff features that doesn’t help the player

Rusben Guzman
2 min readAug 27, 2021

Objective: Make the enemy detect when there is a pickup in front of it and shoot a laser to destroy the pickup.

In the enemy Script I added a new variable called _shootDelay and a public property to get and set the value of this variable. This variable is used as the shoot rate of the enemy.

Then I created a new empty object as a child of the enemy called the detection area. This is the area to detect if there is a powerup and shoot. I added a collider to define the area and a rigidbody to make the collision detection independently of the parent collisions.

Next step was create a new script for the detection area. In that script I create a variable to get the reference to the parent (the enemy). Then I created a coroutine to change the _shootDelay to 0.3 during 2 seconds and assign again the normal _shootDelay value. Finally in that script I used the on trigger enter function to check for the powerup collision and call the coroutine.

In the powerup script I also check for the collision with the laser and the enemy to destroy the powerup.

And that’s it!!!! Now then enemy is able to destroy the pickups. Too bad for the player.

--

--

Rusben Guzman

A Software Engineer passionate about game dev and interactive products with Unity. I consider video games to be the artistic expression of programming.