Bug Fix: Enemy shoots after destroyed

Objective: Create a variable to stop the enemy from shooting after it’s been destroyed.

If you have followed along with my tutorials, then you may notice that sometimes an enemy laser will appear from where an enemy was destroyed and no longer there. This fix is simple and takes one variable.

Let us begin by creating a bool variable and set to true.

We need to add that bool to the if statement that controls the enemy shoot function.

In the enemy destroy method switch the bool value to false.

When the enemy is destroyed the bool value is switched and the shoot function can no longer be called. Today was a simple fix, but sometimes bugs can take you longer to figure out. If you notice a bug, it’s best to address it immediately, it will save you a headache later when the code is more advanced and involved. Remember, don’t be afraid to experiment with you code, and I’ll see you in the next tutorial.