-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoblinEnemy.cs
More file actions
97 lines (77 loc) · 2.35 KB
/
GoblinEnemy.cs
File metadata and controls
97 lines (77 loc) · 2.35 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
using System.Collections;
using Experience;
using UnityEngine;
using UnityEngine.UI;
namespace Enemy.Goblin
{
public class GoblinEnemy : MonoBehaviour
{
[Header("Enemy")]
[SerializeField] private GameObject theEnemy;
[Header("Enemy Variables")]
[SerializeField] private int _enemyHealth;
[SerializeField] private int _baseXp;
private int _calculatedExp;
private bool _isDead;
[Header("Items")]
[SerializeField] private GameObject bag;
[SerializeField] private GameObject itemStash;
[Header("Scripts")]
[SerializeField] private GoblinAI goblinAIScript;
[SerializeField] private GoblinShowHealth goblinShowHealthScript;
[Header("Exp")]
[SerializeField] private GameObject xpContent;
[SerializeField] private GameObject xpBlock;
private GameObject _xpShower;
private Transform _xpNumber;
[Header("Canvas")]
[SerializeField] private GameObject Canvas;
private void Start()
{
//enemyHealth = MonstersData.Instance.GoblinHealth;
//_baseXp = MonstersData.Instance.GoblinExp;
goblinAIScript = GetComponent<GoblinAI>();
goblinShowHealthScript = GetComponent<GoblinShowHealth>();
}
private void DeductPoints(int _damageAmount)
{
_enemyHealth -= _damageAmount;
}
private void Update()
{
if (_enemyHealth <= 0)
{
if (_isDead == false)
{
StartCoroutine(DeathGoblin());
}
}
}
private IEnumerator DeathGoblin()
{
goblinAIScript.enabled = false;
goblinShowHealthScript.enabled = false;
_isDead = true;
_calculatedExp = _baseXp * GlobalExp.CurrentLevel;
GlobalExp.CurrentExp += _calculatedExp;
itemStash.transform.SetParent(Canvas.transform);
itemStash.SetActive(false);
_xpShower = Instantiate(xpBlock, xpContent.transform);
_xpShower.SetActive(true);
_xpShower.transform.SetParent(xpContent.transform);
_xpNumber = _xpShower.transform.Find("xpCount/xp");
_xpNumber.transform.GetComponent<Text>().text = "+" + _baseXp;
yield return new WaitForSeconds (0.5f);
GetComponent<BoxCollider>().enabled = false;
GetComponent<CapsuleCollider>().enabled = false;
GetComponent<Rigidbody>().isKinematic = true;
theEnemy.GetComponent<Animation>().Play("death");
yield return new WaitForSeconds (0.5f);
Bag.SetActive(true);
Destroy(_xpShower, 5);
Destroy(theEnemy, 5);
Destroy(itemStash, 900);
Destroy(gameObject, 900);
}
}
}