Contents:

Understanding the Zombies’ Attributes

Alike the Plants, there are varying amounts of zombies from a standard walking one, to one that can use a door as a shield or even a mega-super-zombie. Before we make the base, we should make sure we understand what attributes the zombies will need at the core and what we can iterate and work with in the future.

As expected, Zombies have a Health parameter, Damage/Second, Speed and an Extra Health.

These are dictated as follows:

Accompanying these, Zombies have items within the game they can carry/wear such as a bucket or a road traffic cone, usually adding to the Zombie’s health. We will add these later using the Zombie class as a base.

Let’s Create a Zombie

Now we can create a master Zombie script, and then use that as a basis for our other zombies down the line.

Let’s add in some variables with the parameters we need from the zombies, as well as some new ones to help with a Health system: currentHealth and currentExtraHealth. As well as this, we need an isEating variable to dictate if the zombie is either in an Eating or Moving state.

public GameObject zombieModel;

[Header("Movement")]
[Tooltip("The length of time it will take the Zombie to move one grid space.")]
public float walkingSpeed;

[Header("Attacking")]
public float attackRate;
public float damagePerAttack;

[Header("Health")]
public float maxHealth;
public float currentHealth;
public float maxExtraHealth;
public float currentExtraHealth;

public TextMeshPro healthText;

[Header("Eating")]
public bool isEating;

Now, the basics we need are as follows:

Moving