Module 4 Devlog - A Simple Game


The next goal was to add the traditional functionality of a game to the player and enemies including taking damage and being defeated.

Enemies can now be spawned into the game using an invisible Spawner object, that can be placed anywhere in the scene and will create a specified number of new enemies at a specified rate of time.

 

Enemies have a "trigger" which can detect when it comes into contact with the player.  When this happens, Unity runs an "Event" which can allow simple actions to happen.  In this case, the enemy runs a function to reduce the player's health, and another to spawn a health pack for the player, before "dying" by becoming inactive and disappearing.  I also added UI to illustrate the player's health, including both text and health bar representation, the latter using a number slider to control how much the green bar fills up the red bar.

Health packs use a similar concept to the enemies - when they detect that they are touching they player, they will use a Unity Event to run a function to increase the player's health before making themselves disappear.

As the health packs don't recover as much health as enemies deal out, the player dying will be inevitable.  When the player's health reaches zero, an Event will run to reveal some "Game Over" text, and they player will call a method to destroy itself.  Because the camera is currently attached to the player, when the player is destroyed it too disappears, so the game switches to a "death cam" that is spawned at the point of the player's demise.

Leave a comment

Log in with itch.io to leave a comment.