Let’s talk about an important concept that you’ll find in countless games today, namely Health. Health -sometimes abbreviated to HP for Health Points– is common. It’s normally an attempt to quantify how healthy a character is, such as the player or an NPC. In most cases, HP is represented by a progress bar spanning from 0 to 100. 100 means full health and 0 is death. Naturally, getting damaged by bullets, punches, lava pits, spikes and other dangers reduces your health. Whereas collecting goodies like hearts, turkeys, burgers, and medi-kits will increase- or maybe even fully restore- your health. It’s that simple. Or is it? Well. As we’ll see in this article, coding health can be deceptively simple. Simple to make, but it’s easy to overlook optimisation. We’ll be working here with the Unity engine- but the same ideas apply across all tools. So even if you’re working in Godot, GameMaker or Unreal, you’ll encounter similar problems. So let’s create a general purpose health script that can be added to any in-game character. Both the Player and NPCs- and even objects like swords and shields.