-
Notifications
You must be signed in to change notification settings - Fork 0
/
MagicEleRunner.cs
303 lines (251 loc) · 10.3 KB
/
MagicEleRunner.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class MagicEleRunner : MonoBehaviour, IdamageableStatus<string, int>
{
private Rigidbody rb;
private float distance;
public float attack_range;
public float move_speed;
public float current_health;
public float max_health;
private float timescale_multi;
public int damage;
private bool hit_check;
public GameObject explode_prefab;
private float fill_amount;
public GameObject HP_Fill_bar;
public GameObject HP_background_bar;
public GameObject floating_damage;
private GameObject float_damage_inst;
public GameObject magic_ele_ragdoll;
private AudioSource _as;
private Animator animator;
//public bool isAttacking;
private bool Has_Attacked;
private bool stop_moving;
private bool side_move;
private int random_direction;
private int walk_threshold = 6;
private int run_threshold = 15;
private bool ground_check = true;
private SkinnedMeshRenderer mesh;
public Material[] base_material;
GameObject exp_holder;
public GameObject exp_prefab;
void Start()
{
hit_check = true;
stop_moving = false;
_as = GetComponent<AudioSource>();
exp_holder = GameObject.Find("Exp Holder");
timescale_multi = 1.0f;
rb = transform.GetComponent<Rigidbody>();
animator = GetComponent<Animator>();
current_health = max_health;
mesh = transform.GetChild(1).transform.GetComponent<SkinnedMeshRenderer>();
base_material = new Material[1] { mesh.material };
if (Basics.instance.Main_Game_Timer < 600)
{
damage = (int)(damage * 1.5f);
}
}
void FixedUpdate()
{
distance = Vector3.Distance(Basics.instance.Player.transform.position, transform.position);
//Get in range
if (distance >= attack_range)
{
Vector3 Targetposition = new Vector3(Basics.instance.Player.transform.position.x, transform.position.y, Basics.instance.Player.transform.position.z);
transform.LookAt(Targetposition);
} else
{
transform.LookAt(Basics.instance.Player.transform.position);
}
if (!stop_moving)
{
transform.Translate(Vector3.forward * move_speed * Time.deltaTime * timescale_multi);
}
//Death
if (current_health <= 0.0f)
{
//StartCoroutine(Death());
//PlayerStats.instance.Experience_Count++;
Vector3 exp_spawn = transform.position;
exp_spawn.y += 5;
GameObject exp_inst = Instantiate(exp_prefab, exp_spawn, Quaternion.identity);
exp_inst.transform.parent = exp_holder.transform;
GameObject ragdoll_inst = Instantiate(magic_ele_ragdoll, transform.position, transform.rotation);
//animator.SetBool("Death", true);
Destroy(gameObject);
Destroy(ragdoll_inst, 5);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.tag == "Player" && !stop_moving)
{
stop_moving = true;
StartCoroutine(Explode_Delay());
}
}
//private void OnCollisionEnter(Collision collision)
//{
// if (collision.transform.tag == "Player" && !stop_moving)
// {
// stop_moving = true;
// StartCoroutine(Explode_Delay());
// }
//}
IEnumerator Explode_Delay()
{
_as.Play();
transform.GetChild(1).transform.GetComponent<Animator>().SetBool("Explode", true);
animator.SetBool("Explode", true);
animator.Play("ExplodePulse");
yield return new WaitForSeconds(2);
GameObject explode_inst = Instantiate(explode_prefab, transform.position, transform.rotation);
Destroy(explode_inst, 2);
if (hit_check)
{
Collider[] damaged_enemies = Physics.OverlapSphere(transform.position, 10);
foreach (Collider col in damaged_enemies)
{
if (col.tag == "Player")
{
IDamageable<float> damageable = col.GetComponent<IDamageable<float>>();
if (damageable != null)
{
damageable.Damage(damage);
}
}
}
hit_check = false;
Vector3 exp_spawn = transform.position;
exp_spawn.y += 5;
GameObject exp_inst = Instantiate(exp_prefab, exp_spawn, Quaternion.identity);
exp_inst.transform.parent = exp_holder.transform;
}
Destroy(gameObject);
}
public void Damage(float Spell_Damage)
{
StartCoroutine(Allow_Physics());
float damage_total;
damage_total = Spell_Damage;
current_health -= Spell_Damage;
float_damage_inst = Instantiate(Basics.instance.Floating_Damage_Holder, new Vector3(transform.position.x, transform.position.y, transform.position.z), Quaternion.identity);
float_damage_inst.transform.GetChild(0).GetComponent<TMP_Text>().text = damage_total.ToString();
Destroy(float_damage_inst, 1);
//Enemy health bar
if (!this.HP_background_bar.activeSelf)
{
this.HP_background_bar.SetActive(true);
this.HP_Fill_bar.SetActive(true);
}
fill_amount = (current_health / max_health);
HP_Fill_bar.GetComponent<Image>().fillAmount = fill_amount;
}
//IEnumerator Attack()
//{
// int attack_select = Random.Range(0, 10);
// switch (attack_select)
// {
// case int n when n < 9:
// {
// if (timescale_multi != 0)
// {
// //Standard Bullet attack
// //animator.Play("SpellReady");
// stop_moving = true;
// animator.SetBool("Attacking", true);
// chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// chargeup_instance.transform.SetParent(transform);
// //chargeup_instace.transform.SetParent()
// yield return new WaitForSeconds(1.5f);
// //animator.Play("Attack01");
// GameObject bullet_instance = Instantiate(bullet_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// Destroy(bullet_instance, 2);
// animator.SetBool("Attacking", false);
// stop_moving = false;
// attack_timer = 0;
// }
// else yield return null;
// }
// break;
// case 9:
// //Homing missile attack
// stop_moving = true;
// animator.SetBool("Attacking", true);
// chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// chargeup_instance.transform.SetParent(transform);
// //chargeup_instace.transform.SetParent()
// yield return new WaitForSeconds(1.5f);
// GameObject missile_instance = Instantiate(missile_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// Destroy(missile_instance, 6);
// animator.SetBool("Attacking", false);
// stop_moving = false;
// attack_timer = 0;
// break;
// //case 4:
// // //Field aoe attack
// // stop_moving = true;
// // animator.SetBool("Attacking", true);
// // chargeup_instance = Instantiate(chargeup_prefab, attack_spawner.transform.position, attack_spawner.transform.rotation);
// // chargeup_instance.transform.SetParent(transform);
// // //chargeup_instace.transform.SetParent()
// // yield return new WaitForSeconds(1.5f);
// // GameObject storm_instance = Instantiate(storm_prefab, Basics.instance.Player.transform.position, attack_spawner.transform.rotation);
// // Destroy(storm_instance, 8);
// // animator.SetBool("Attacking", false);
// // stop_moving = false;
// // attack_timer = 0;
// // break;
// }
// Has_Attacked = false;
// //case int n when n == 5 || n == 6:
// // //Random movement
// // newpos = waypoints[Random.Range(0, 4)].position;
// // combat_moving = true;
// // yield return new WaitForSeconds(2);
// // combat_moving = false;
// // attack_timer = 0;
// // break;
//}
IEnumerator Allow_Physics()
{
rb.drag = 1;
ground_check = false;
yield return new WaitForSeconds(4);
rb.drag = 10;
ground_check = true;
}
public IEnumerator Set_Status(string type, float duration)
{
switch (type)
{
case "frost":
mesh.material = Basics.instance.Frost_Status_Mat;
break;
case "air":
Material[] air_material = new Material[2] { base_material[0], Basics.instance.Air_Status_Mat };
mesh.materials = air_material;
break;
case "earth":
mesh.material = Basics.instance.Earth_Status_Mat;
break;
}
timescale_multi = 0;
animator.speed = 0;
yield return new WaitForSeconds(duration);
mesh.materials = base_material;
timescale_multi = 1;
animator.speed = 1;
}
public void Status(string Status_Effect, int duration)
{
StartCoroutine(Set_Status(Status_Effect, duration));
}
}