diff options
author | chai <215380520@qq.com> | 2024-03-13 11:38:18 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2024-03-13 11:38:18 +0800 |
commit | 134f1deb971b0514a26e04e23926f91983a5497f (patch) | |
tree | d790681bb000c07abae9f557a7d0ef2442fac467 /_ActiveRagdoll/Damagable.cs | |
parent | 6ce8b9e22fc13be34b442c7b6af48b42cd44275a (diff) |
* move
Diffstat (limited to '_ActiveRagdoll/Damagable.cs')
-rw-r--r-- | _ActiveRagdoll/Damagable.cs | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/_ActiveRagdoll/Damagable.cs b/_ActiveRagdoll/Damagable.cs new file mode 100644 index 0000000..667cd5e --- /dev/null +++ b/_ActiveRagdoll/Damagable.cs @@ -0,0 +1,54 @@ +using UnityEngine; +using UnityEngine.Events; + +public class Damagable : MonoBehaviour +{ + public float multiplier = 1f; + + private PlayerDeath playerDeath; + + public UnityEvent outOfLiveEvent; + + public UnityEvent damageEvent; + + public float health = 100f; + + private float currentHealth; + + private bool dead; + + private Rigidbody rig; + + private void Start() + { + rig = GetComponent<Rigidbody>(); + currentHealth = health; + playerDeath = base.transform.root.GetComponent<PlayerDeath>(); + } + + private void Update() + { + } + + public void TakeDamage(Vector3 damage, Vector3 hitPoint) + { + damage *= multiplier; + if ((bool)playerDeath) + { + playerDeath.TakeDamage(damage, hitPoint, rig); + return; + } + damageEvent.Invoke(); + currentHealth -= damage.magnitude; + if (currentHealth < 0f && !dead) + { + dead = true; + outOfLiveEvent.Invoke(); + } + } + + public void RefillHP() + { + currentHealth = health; + } +} |