Week 5
Self Study 4 -- Make it a game
It was finally time to add some mechanics to make it a playable game. I wanted to turn it into a Pacman style game, where the player avoids the enemies until they have a power up to collect points. The first thing was to do was add some spawners for the slimes, which trigger a co-routine when the player enters that area. I initially had the spawner set a flag on each enemy that would be used to keep track of the number of enemies currently active, and allow more to spawn as they were disabled. I later modified the script to use an object pooling system instead, having the spawner store a list of enemy game objects, and reusing them as they were disabled (completely unnecessary for this number of objects, but more optimised I guess).
Of course, the enemies have to damage the player when they collide with them - using a trigger that detects the player object, and calling a function to decrease their health, and then disabling the enemy game object so it can be re-used. After that, it was time to add a power up. I modelling a watermelon for it - because I happened to be eating one at the time (truly innovative), and included a short animation. I added a function to the player that is called when collecting the power up, which starts a co-routine that makes the player invincible for a short period. They will also switch from taking damage to collecting points from enemies, who will try to run away while the power up is active (and refuse to spawn). The escape movement also uses the navmesh agent and it is genuinely hard to catch them sometimes.
Lastly, I added some UI elements to show the players health and score, as well as some "Game Over" text when they die. This currently managed through the player object, but it might be better to create a dedicated game manager to store and display this instead. I didn't end up adding an explosion effect though, because it just felt wrong to make the Tanuki explode 👀.
Sorry about the GIF quality, I had to stick them in a black hole to compress enough to upload.