ambrose01

playerHealth.cs

Oct 21st, 2025
805
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.51 KB | Source Code | 0 0
  1. using UnityEngine;
  2.  
  3. public class PlayerHealth : MonoBehaviour
  4. {
  5.     public int maxHealth = 100;
  6.     private int currentHealth;
  7.  
  8.     void Start() => currentHealth = maxHealth;
  9.  
  10.     public void TakeDamage(int amount)
  11.     {
  12.         currentHealth -= amount;
  13.         Debug.Log("Player took damage. Current Health: " + currentHealth);
  14.         if (currentHealth <= 0)
  15.         {
  16.             Die();
  17.         }
  18.     }
  19.  
  20.     void Die()
  21.     {
  22.         Debug.Log("Player Died.");
  23.         // Add death logic
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment