Advertisement
GoodNoodle

Health

Jul 3rd, 2021
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.99 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class Health : MonoBehaviour
  6. {
  7.    public float health = 100f;
  8.  
  9.     private void Start()
  10.     {
  11.         health = GetComponent<BaseStats>().GetStat(Stat.Health);
  12.     }
  13.     public  void TakeDamage(GameObject instigator, float damage)
  14.     {
  15.         Debug.Log(gameObject.name + "Took Damage" + damage);
  16.         health = Mathf.Max(health - damage, 0);
  17.         print(health);
  18.        
  19.         if(health <= 0)
  20.         {
  21.             GetComponent<Animator>().SetTrigger("Die");
  22.             AwardEXP(instigator);
  23.         }
  24.     }
  25.  
  26.     private void AwardEXP(GameObject instagator)
  27.     {
  28.        XP exp = instagator.GetComponent<XP>();
  29.         if (exp == null) return;
  30.  
  31.         instagator.GetComponent<XP>().GainExp(GetComponent<BaseStats>().GetStat(Stat.ExpReward));
  32.     }
  33.  
  34.     public float GetPercentage()
  35.     {
  36.         return 100 * (health / GetComponent<BaseStats>().GetStat(Stat.Health));
  37.     }
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement