/
EnemyHealth.cs
74 lines (46 loc) · 1.38 KB
/
EnemyHealth.cs
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
using UnityEngine;
public class EnemyHealth : MonoBehaviour
{
public int startingHealth = 100;
public int currentHealth;
public AudioClip deathClip;
AudioSource enemyAudio;
CapsuleCollider capsuleCollider;
bool isDead;
void Awake()
{
capsuleCollider = GetComponent<CapsuleCollider>();
// Setting the current health when the enemy first spawns.
currentHealth = startingHealth;
}
void Update()
{
}
public void TakeDamage(int amount, Vector3 hitPoint)
{
if (isDead)
{
return;
}
// Reduce the current health by the amount of damage sustained.
currentHealth -= amount;
// If the current health is less than or equal to zero
if (currentHealth <= 0)
{
Death();
}
}
public void Death()
{
// The enemy is dead.
isDead = true;
Destroy(gameObject);
// Turn the collider into a trigger so shots can pass through it.
capsuleCollider.isTrigger = true;
// Change the audio clip of the audio source to the death clip and play it (this will stop the hurt clip playing).
//GetComponent<AudioSource>().clip = deathClip;
//GetComponent<AudioSource>().Play();
MuziekManager.Instance.Play(deathClip);
Debug.Log("DeathClip");
}
}