Zombie Runner (prototype)
Status
Completed
Project Type
Personal
Software
Unity
Language(s)
C#
Role(s)
Gameplay programming
Zombie Runner is a prototype of a 3D first-person shooter where players survive by shooting zombies. They have multiple weapons to use and a flashlight to help light the way. But beware, it will diminish over time!

When you download the and unzip the folder, and are having trouble opening the game try right-clicking the game and click on "Open".

Zombies can detect when the player is near or when the player shoots at them. Once provoked, they will relentlessly pursue them until they are killed.

”animated”

”animated”

The snippet below makes the zombie decide what to do when the player provokes it.




The zombie has a nav mesh agent attached to it so it can move around in the world. Here I am using the agent to decide if the zombie continues to chase the player (if not already attacking) or attack the player (if it caught up to the player). Line 75 is what makes the zombie lock on to the player.



The Player can equip a different weapon (3 different kinds) by pressing the 1, 2 or 3 keys on a keyboard:
1 - Shotgun: Shots do more damage but take the longest to reload.
2 - Pistol: Shots do the least amount of damage but can reload the fastest.
3 - Carbine: Shots do moderate damage and reload time is greater than the pistol's but less than the shotgun's.

Each weapon also uses it's own kind of ammo.

”animated”

In another method, the value of currentWeapon changes when the player presses 1, 2, or 3. After that, in this method, I iterate through all the weapon's transforms, using weaponIndex as the starting point. If it matches what currentWeapon is, then I set that as the weapon the player is holding. otherwise the weapon is turned off.




I used enums to represent the different kinds of ammo. Bullets have an index of 0, Shells get an index of 1 and Rockets get an index of 2.



I used a private class to represent the ammo slot, which is composed of an AmmoType enum and an int variable representing the amount of ammo in this ammo slot. That way I don't have to have a separate variable for each ammo type in the Player class. Also, I can see how much of that ammo is currently there all in one place.



This is used to get the right AmmoSlot anytime I need to do that in code. I just need to pass in the AmmoType, which will be assigned in Unity's inspector for each weapon (The pistol is assigned bullets while a shotgun is assigned shells, etc). Methods that increase or decrease ammo use this method to know which ammo to change.


Ammo Pickup: each weapon has a different pickup. The one shown here is for pistols. The amount of ammo the player has is displayed in the top right.

”animated”

Once colliding with the player, the pickup will search them for the Ammo component (representing the ammo slot). That component has a method to increase the amount of ammo.


Battery Pickup: this pickup increases the intensity and angle of the player's flashlight, which runs out of power over time.

”animated”

The FlashLightSystem is attached to my flashlight object. I placed the flashlight under the MainCamera so it would light the way the player sees. So this pickup needs to search the Player object's children for the flashlight system to be able to replenish the flashlight.


I made the land the player walks on using Unity's Terrian object. The asylum building is made using ProBuilder. This was my first time using both of those but I had a lot of fun with them and hope to use them in future games.

”animated”


”animated”


I used the Animator window to tell the zombies what they should be doing depending on the conditions.



”animated”

I have a method for the "Move", "Attack" and "Die" states. The "Attack" method is really simple. All I need to do is get the Animator and set a bool to true so the zombie gets the "ok" to attack. They might be zombies, but they are still nice people. They'll only attack you if you allow them to.