VOOZH about

URL: https://www.geeksforgeeks.org/c-sharp/health-system-in-unity/

⇱ Health System In Unity - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Health System In Unity

Last Updated : 4 May, 2026

In any game with combat, characters need to take damage and eventually die. A health system tracks this. It determines how many hits a player or enemy can survive before being defeated.

Basic Health Script

This script handles taking damage, healing, and death.

Output:

👁 Basic-Health-Script-In-Unity
Basic Health System In unity
  • TakeDamage() reduces health and destroys object when zero. Heal() restores health. 
  • Mathf.Clamp() keeps the value between 0 and maxHealth (so health never goes above max or below 0).

Connect Shooting to Health

Once you have a health script, connect it to your shooting system.

Get the Health component from the hit object and call TakeDamage() with your weapon's damage value.

Simple Health Bar

A health bar gives players visual feedback of their remaining health.

The slider's max value equals maxHealth. Every frame, the slider updates to match current health.

Healing Pickup

Health pickups allow players to restore health during gameplay.

Output:

When the player touches the pickup, heal them and destroy the pickup object.

Comment
Article Tags:
Article Tags:

Explore