I created a perk that reduces zombie's health, but it only works on the first zombie.

I am specifically avoiding enemy class inheritance, treat Zombie as the base enemy class; here to make it more relatable. Do note that what’s below may seem complicated at a glance because it’s not a solution to your specific issue, it’s a solution to 99% of issues in vast majority of scenarios where damage needs dealing.

This is still somewhat simplified and can be improved further but that should be tackled once we know the scope of the project.


Consider the following:

  • I’ve created an enumerator (official) so I can distinguish between enemy and damage types easily:

    image

    The base enemy class has this variable, each enemy knows who they are if we query them. This one is a zombie:

  • in order to handle Damage Types, I’ve created 1 base damage class, and 3 children:

    image

    image

  • the base class damage describes how damage is done in general:

We take the incoming damage, maybe apply a crit, maybe it’s enough to kill the enemy outright. We then spit out the processed value.

  • normally, the player deals damage (just by clicking enemies for simplicity) like so:

  • the enemy receives said damage:

We use our damage class for processing (see above).

  • the interesting part kicks in when we start using other damage type classes. This is the damage type that allows us to immediately kill zombies (and zombies only!):

Let’s grant the player the new damage type:


Other enemy types remain unaffected:

Note how all the processing, damage mitigation, crits, health can be handled inside the damage classes. We no longer need to clutter the enemies or the player with any of this.

1 Like