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

Kotlin for Interviews series

AWS CDK — A Beginner’s Guide with Examples

Fast way to load device contacts in android programming

Regular Expressions — Part 2

We are happy to announce that FistNFT and PGNFT CLUB held their first AMA!

Eat your own neXboard

Create a Kubernetes Cluster using Kind

Git Commands for Beginners

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

Learning Unity — How To Make A Loading Screen

Creating An Advanced 2D Player Controller Without Any Unity Components! (Part 1)

2D Mobile: Designing Enemies Using Abstract Classes

Creating a Keystore File within Unity