Phase 2: The Negative

Simon Leen
2 min readJun 24, 2021

--

Objective: Create a collectable that has a negative effect on the player.

For the negative, a collectable that causes one hit to the player so either the shield reduces if active or the player loses a life. It also takes 5 ammo or all remaining ammo if less that 5.

The negative collectable

The setup for the prefab, animation and movement are the same as in previous posts(setup, animation, add to modular system). The logic is slightly different.

When the player triggers with the OnTriggerEnter method on the powerup script, a public void Damage method on the player gets called from the powerup script. The damage method first calls the TakeDamage method on the player. This checks if shields are active and if so reduces the shield or if the shield is not active reduces the players lives by 1 or destroys the player if on the last life. It then runs an if statement to check if the players ammo is less than 5 and if so sets the ammo at 0. If the ammo is 5 or higher it reduces the ammo by 5 then. Once the ammo has been set it calls the UI Manager UpdateAmmo method and passes the now current player ammo to update the Ammo UI.

Damage Method

In the next post, we will look at updating the enemies movement.

--

--

No responses yet