Week 4 - Self Study


Using the same scene from the previous tutorial, plus the supplied assets, I made a simple little game where the player moves the character around the environment using directional keys, whilst enemies chase after them. As mentioned in my previous post, a Navigation Mesh is being used for the enemy navigation, but now the player loses health every time an enemy makes contact with them. Enemies are being spawned in at 3 locations using a script which allows me to control how often they spawn, and how many to spawn before stopping (in this example I set this to 5) - as seen below.

 


A new addition to the scene are the red health pickups, the models for which I made using ProBuilder! Each time the player walks into one of these pickups, their health is increased by a given value (in my case I just made it increase by 1). If I had a bit more time, I would have really liked to add just a simple script which made the model slowly rotate and bob up and down in the air.

It's worth mentioning that these functionalities - enemies touching the player and reducing their health, enemies and health pickups disappearing after touching the player, and health pickups affecting the player - are all being done through something called UnityEvents. I have used this previously when making my character open a door to pass through it (see Week 3 - Tutorial). Using this system, I can avoid writing code to undertake really simple tasks, such as the ones mentioned before, by defining an event inside the script. In this case we want to check for a trigger collision between a given object and the player (this is our event), when this occurs, I can define inside the Unity inspector (shown above) what effects should take place rather than writing a separate script for each use case. This offers a great degree of flexibility with less overall code - although more complex functionality might be difficult to do this way, and might warrant its own script.

Finally, a simple particle effect was added when the player dies; this was done using a separate object with a "Particle System" contained within it which was spawned upon the player's death. If I had simply attached this particle system to the player, it would not display properly since the player object is being disabled!

Leave a comment

Log in with itch.io to leave a comment.