2D Shooter: Squashing Bugs

Sabrina Windsor
2 min readSep 1, 2021

--

Objective: Let’s fix some bugs revolving enemy shooting so that they don’t shoot once they’re dead and do not kill other enemies.

First off, the reason why enemies were able to shoot after they die, was because there was no variable checking if they were dead and would not be able to shoot. So let’s add one. In start, set it to true.

Now let’s put it the update method where we initiate shooting.

Now in the code wherever we destroy the object we want to set it this bool variable to false. This is what will stop the enemy from shooting. For efficiency, we can’t write before any if checks, as the enemy will die from any detectable collisions.

Now for fixing friendly fire, the simple way is to give the enemy laser its own tag. We also want to make sure the laser prefabs within it do not have the laser tag. Give the enemy laser prefab a tag “enemy laser”, and to be safe, give it to the laser sub objects. Do not override these, because we don’t want all lasers being classified as enemy lasers and messing with other collisions.

And that’s all there is to it!

--

--

Sabrina Windsor

Currently learning to code with the help of GamedevHQ in order to someday my my game ideas come to life!