Health System

Health System

The Advanced Turret AI System comes with a lightweight HealthSystem component. It's used for targets like enemies or destructible objects that turrets interact with.


🩺 Overview

Attach HealthSystem to any GameObject you want to receive damage from turrets. It listens for hits and tracks current health.

This component works out of the box with the TurretController and TurretProjectile scripts.


⚙️ Inspector Fields

Field
Description

Max Health

Total hit points before destruction

Current Health

Current HP (can be changed at runtime)

Fill Health On Start Up

If true, sets current HP to max when the scene loads

On Death (UnityEvent)

Fires when health drops below 0


💥 Taking Damage

Turret projectiles call:

enemyHit.Invoke(enemy, turretDamage);

which triggers this internally:

This reduces health on the enemy’s HealthSystem. You can also call it from your own scripts.


🧨 Destroying Objects

The HealthSystem can auto-destroy objects via:

Call this manually or from the On Death event.


✅ Quick Setup

  1. Add HealthSystem to any GameObject you want turrets to damage.

  2. Enable Fill Health On Start Up.

  3. (Optional) Connect the On Death event to play VFX, sounds, or destroy the object.

💡 Don’t forget to tag these objects as Enemy so the turret can detect and target them.

Last updated