Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class Health : MonoBehaviour
- {
- public float health = 100f;
- private void Start()
- {
- health = GetComponent<BaseStats>().GetStat(Stat.Health);
- }
- public void TakeDamage(GameObject instigator, float damage)
- {
- Debug.Log(gameObject.name + "Took Damage" + damage);
- health = Mathf.Max(health - damage, 0);
- print(health);
- if(health <= 0)
- {
- GetComponent<Animator>().SetTrigger("Die");
- AwardEXP(instigator);
- }
- }
- private void AwardEXP(GameObject instagator)
- {
- XP exp = instagator.GetComponent<XP>();
- if (exp == null) return;
- instagator.GetComponent<XP>().GainExp(GetComponent<BaseStats>().GetStat(Stat.ExpReward));
- }
- public float GetPercentage()
- {
- return 100 * (health / GetComponent<BaseStats>().GetStat(Stat.Health));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement