top of page

Play Game

Notes:

     For our second project, we made a generic health, lives, and score template that we can use in later games. Our template has a GameController with functions to change the player's health with ChangeHealth, change the score with ChangeScore, change the scene with NextScene and Restart, and show the win and game over screens with Win and GameOver.

    The player is controlled by a PlayerController with an AudioSource to play the sound effects for different events. The pickup spawns a ParticleSystem when it is collected and destroyed after a few seconds. We made prefabs out of the Player, Enemy, HealthPickup, GemPickup, GameController and Canvas for easy use in other games.

Code snippets

This code is run when you click the next level button. First, it checks to make sure there is another scene to load, and then if there is, it loads the next scene. Otherwise, it reloads the current scene. 

This code is run when the score is changed. First, it tells the player to play the sound for pickup collections. It then changes the score by the amount passed into the function. Then, it updates the text to show the new score. If the score is above or equal to the score required to win, it calls the function that handles winning the game.

This code is functionally similar to the ChangeScore function above, however, it has some more logic to handle having a max number of hearts. First, it decides if it should play the heal or hurt sound and then plays that sound. Then, it changes the health by the amount but keeps it between 0 and the max health. Then it loops through the hearts and sets them to be visible if they should be visible. If the health is 0, it calls the function to handle GameOver

bottom of page