summaryrefslogtreecommitdiff
path: root/_ActiveRagdoll/Damagable.cs
blob: 667cd5e2ce03bc42e49637de7e11fa503f059ad6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
	}
}