-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLivingEntity.cs
More file actions
42 lines (35 loc) · 810 Bytes
/
LivingEntity.cs
File metadata and controls
42 lines (35 loc) · 810 Bytes
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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LivingEntity : MonoBehaviour, IDamageable
{
public float startingHealth;
protected float health;
protected bool dead;
public event System.Action OnDeath;
protected virtual void Start()
{
health = startingHealth;
}
public void TakeHit(float damage, RaycastHit hit)
{
TakeDamage(damage);
}
public void TakeDamage (float damage)
{
health -= damage;
if (health <= 0 && !dead)
{
Die();
}
}
protected void Die()
{
dead = true;
if( OnDeath != null)
{
OnDeath();
}
GameObject.Destroy(gameObject);
}
}