Modular Health System Pt.01- Game Dev Series 125

Objective: creating a health system that would work on both enemy and Player.

One of the efficient ways to create a game is creating modular system.We had created abstract class and interface, which are all kind of modular system. In this article, we would create a simpler modular system as health system.

New script

This health system would be built as a new script.
Create a new script and create a public method called “Damage”.

And we also need some variables to set the max and min health value.

This public method “Damage” would be the core of this script.
Next, we will need to make this method calculate the current health when taking damage. Thus, we need to pass in the damage amount when it was called by other scripts.

The Health script is ready, now we can put this to both Player and Enemy.

Damage on Enemy

To damage the enemy, we can simply use the crosshair with mouse clicking.
Open Shoot script and add few lines to execute shoot.

With these codes, when aiming on Enemy and clicking mouse, it should locate the Health script. If it has, then deal it with 5 damage.
Now back to editor and assign the max and min health to Enemy.

And we can test out the damage result.

The next article we would continue making damage to Player from Enemy.




A passionate gamer whose goal is to work in video game development.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

It is one of the other popular methods of incorporating machine learning in apps, mostly when you…

C#: Getting to know variables

Android Jetpack Series with Goku

In a Nutshell: Object-Oriented Programming Explained

SpaceGate uses a variety of indications

Service Virtualization

Core Web Vitals FID Case Study

Kubernetes Services

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Cleaning up the Homing Missile code

Different Lights in Unity.

Creating a HUD

Creating a Simple Cooldown System In Unity