-
Notifications
You must be signed in to change notification settings - Fork 0
/
Enemy.cs
49 lines (40 loc) · 1.04 KB
/
Enemy.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
using UnityEngine;
public class Enemy : MonoBehaviour
{
[SerializeField] GameObject DeathFx;
[SerializeField] Transform parent;
[SerializeField] int scorePerHit = 2;
[SerializeField] int scorePerDeath = 20;
[SerializeField] int hits = 10;
ScoreBoard scoreBoard;
void Start()
{
AddBoxCollider();
scoreBoard = FindObjectOfType<ScoreBoard>();
}
private void AddBoxCollider()
{
Collider colliderr = gameObject.AddComponent<BoxCollider>();
colliderr.isTrigger = false;
}
private void OnParticleCollision(GameObject other)
{
ProcessHit();
if (hits <= 0)
{
KillEnemy();
scoreBoard.ScoreHit(scorePerDeath);
}
}
private void ProcessHit()
{
scoreBoard.ScoreHit(scorePerHit);
hits--;
}
private void KillEnemy()
{
GameObject FX = Instantiate(DeathFx, transform.position, Quaternion.identity);
FX.transform.parent = parent;
Destroy(gameObject);
}
}