Advertisement
leomovskii

Health

Oct 5th, 2024
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.27 KB | None | 0 0
  1. using UnityEngine;
  2.  
  3. public class Health : MonoBehaviour {
  4.  
  5.     public int currentHealth = 10;
  6.  
  7.     public void Damage(int value) {
  8.         currentHealth -= value;
  9.         if (currentHealth < 0) {
  10.             currentHealth = 0;
  11.         }
  12.  
  13.         if (currentHealth == 0) {
  14.             Destroy(gameObject);
  15.         }
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement