Hit System with Interfaces in Unity

Jared Amlin
Nerd For Tech
7 min readMar 22, 2024

--

Have you ever wondered how first and third person shooter games handle their hit system? You know the kind I am talking about, where headshots will kill an opponent while a body or limb shot will take more than one hit. Then you get various animations that play depending on where the enemy was hit when they took damage or died.

Most of the damage implementation I have done in the past involved a single object with a collider on it. I have to admit, I still have no idea how AAA gaming studios construct their hit systems, but this is the solution I came up with, using the Unity Documentation as my only resource.

Scripting

I wanted to make this system scalable, reusable, and designer friendly, so I got started with an Interface! This IHittable interface is the base class for all objects that need to be hit. This is what a Raycast from a gun object or camera will use to pass in a damage amount to the inheriting class, which leaves flexibility for more weapons to pass in their own various amount of base damage.

public interface IHittable
{
void HitDamage(int damageAmount);
}

The Hit class, inherits from both MonoBehavior and IHittable. Multiple inheritance is of course, one of the many benefits of using interfaces. This script can be attached to any object with a collider that you…

--

--

Jared Amlin
Nerd For Tech

I am an artist and musician, that is currently diving headfirst into game development with C# and Unity3D.