Files
CartoonFPS/Assets/Scripts/PlayerHealthController.cs
SHOUTING_PIRATE c76abc159d working on enemies
2025-08-05 15:34:40 +01:00

27 lines
788 B
C#

using UnityEngine;
public class PlayerHealthController : MonoBehaviour
{
public static PlayerHealthController instance; // Singleton instance for easy access
private void Awake()
{
instance = this; // Set the singleton instance
}
public float maxHealth;
private float currentHealth;
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
currentHealth = maxHealth; // Initialize current health to maximum health
}
public void TakeDamage(float damageAmount)
{
currentHealth -= damageAmount; // Reduce current health by the damage amount
if (currentHealth <= 0)
{
Debug.Log("Player is dead!"); // Log player death
}
}
}