Unity Game-jam: FPS Microgame

Unity game-jam
2023

This game-jam was a challenge to myself shortly after baby-builder. I wanted to learn how to add features and functionality to project that already had an existing codebase, as well as working with the unity event system. Here I wanted to add an extra ability for the player, show them their current score, and save the high-score on a per-system basis. Just like with the unreal game-jam I gave myself 24 hours with 6 hours of sleep.

Player input mapping

First I added the "ActivateAbility" input to Unity's Input Manager and defined a corresponding string constant k_ActivateAbility in the GameConstants class. A bool GetActivateAbilityDown is added to the PlayerInputHandler script to track when the ability input is pressed down. In the PlayerInputHandler's Update method, GetButtonDown is called with the k_ActivateAbility constant to check if the ability button was newly pressed this frame. If the input is detected, the PlayerCharacterController script checks the GetActivateAbilityDown bool. In the PlayerCharacterController, if the ability button is pressed (GetActivateAbilityDown is true), the AbilityEffect function from the Ability script attached to the same game object is called. This allows the player character to trigger the special ability by pressing the pre-defined input button. The input setup centralizes the ability activation into a single reusable input defined in the Unity Input Manager.


Slow-motion Ability

The Ability script defines variables like AbilityDuration and AbilityActive. In Start(), it gets the PlayerCharacterController and adds a listener for the OnEnemyKilled event. The AbilityEffect function starts/stops a coroutine based on AbilityActive, adjusting AbilityDuration and resetting effects. The coroutine applies effects while elapsed time is less than AbilityDuration. Inside the coroutine, a while loop continuously applies the ability effects and yields until the elapsed time exceeds AbilityDuration. The effects applied likely involve modifying player stats or abilities temporarily. OnEnemyKilled increases AbilityDuration by 5f each time an enemy is killed, allowing the player to extend the ability duration. OnDestroy removes the event listener to prevent memory leaks. The script demonstrates the use of coroutines for time-based effects, event handling for gameplay events, and basic component interaction between scripts.


Kill-count

The UniKillCount script tracks the number of enemies killed in the current level. It adds a listener for OnEnemyKilled in Start(), increments a kill counter in the event function, and displays the count using a UI text element. OnDestroy removes the listener.


High-score

The HighScoreManager checks if the current kill count is higher than the stored high score in PlayerPrefs. It listens for the OnAllObjectivesCompleted event, compares kill counts, and updates the PlayerPrefs high score if the current count is higher.

The HighScoreText script retrieves the high score integer from PlayerPrefs, converts it to a string, and displays it on a UI text element prefixed with "Your highscore in this level:".

Previous
Previous

VR Baby Builder