-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuardWeakSpot
More file actions
71 lines (57 loc) · 1.93 KB
/
Copy pathGuardWeakSpot
File metadata and controls
71 lines (57 loc) · 1.93 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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GuardWeakSpot : MonoBehaviour
{
public GameObject parent;
bool setNextPhase = false;
bool setFinalPhase = false;
public AudioClip hurtSound;
// Start is called before the first frame update
void Start()
{
parent = GameObject.FindGameObjectWithTag("Guard");
}
// Update is called once per frame
void Update()
{
}
private void OnTriggerEnter2D(Collider2D other)
{
//if the enemy is colliding with an attack, take damage
if (other.gameObject.tag == "Attack")
{
//take damage from attack & play sound
transform.GetComponentInParent<GuardScript>().DoDamage(1);
GetComponent<AudioSource>().PlayOneShot(hurtSound);
//get the current health
int myHealth = transform.GetComponentInParent<GuardScript>().GetHealth();
if (myHealth <= 0)
{
//out of health, guard died
PlayerController playerCont = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
playerCont.StartFrayFight();
Destroy(parent);
Destroy(gameObject);
}
else if (myHealth <= 10 && !setNextPhase)
{
//set the next animation
GetComponent<Animator>().Play("Base Layer.Half Health anim");
setNextPhase = true;
}
else if (myHealth <= 5 && !setFinalPhase)
{
//set the final animation
GetComponent<Animator>().Play("Base Layer.Low Health anim");
setFinalPhase = true;
}
}
}
public void ResetPhases()
{
setFinalPhase = false;
setNextPhase = false;
GetComponent<Animator>().Play("Base Layer.Full Health anim");
}
}