My journey becoming a Unity game developer: Phase-43

Rhett Haynes
2 min readAug 6, 2021

Objective: Fix enemies being able to shoot the player after they die. Pressing the Left-Shift key to make the player’s thrust speed double in speed.

Enemies are able to shoot the player after being hit because of the delay in time within the Destroy() method we used to allow the OnEnemyDeath animation trigger to play in its entirety.

Enemy is destroyed after 2.4 seconds
Enemies are still shooting after death animation.

Therefore, go back into the Enemy script and head down to the OnTriggerEnter2D() function. Inside both IF conditions for the Player and Laser, I will destroy the Enemy script component to prevent the dead enemy from shooting at me as though I have ghosts playing in this game. This should allow the enemy’s death animation to play, as well allowing the enemy to be destroyed in the time set inside the Destroy() method.

Destroying the Enemy script component before the enemy itself.
Enemies not allowed to shoot the player after they die.

One more thing is I added a speed boost when the user holds down the Left-Shift key. The player’s speed with increase by 2 regularly and when the player collects the Speed powerup. Start by going in the Player script, creating a variable name thrustSpeed and multiply the _speed variable by 2. Inside the PlayerMovement() method, add an IF condition to check if the user is pressing down on the Left-Shift key. If the user is, we will multiply the direction the player is moving in by thrustSpeed and multiply by real-time. If not, we will multiply the direction the player is moving in by the _speed variable and the actual real-time.

Left-Shift key will move the player by the thrustSpeed values.
Holding down the Left-shift key to double the player’s speed including speed powerup.

--

--