Advertisement
Ychenik

Health

Apr 8th, 2020
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.61 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Heal : MonoBehaviour
  6. {
  7.     public float startHp;
  8.     public float hp;
  9.     void Start()
  10.     {
  11.         hp = startHp;
  12.     }
  13.  
  14.     // Update is called once per frame
  15.     public void DealDamage( float damage )
  16.     {
  17.         hp -= damage;
  18.  
  19.         if (hp <= 0)
  20.         {
  21.             Die();
  22.         }
  23.     }
  24.  
  25.     void Die()
  26.     {
  27.         if (gameObject.tag == "Player")
  28.         {
  29.             Debug.Log("You died");
  30.         }
  31.  
  32.         else
  33.         {
  34.             Destroy(gameObject);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement