-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwordBehaviour.cs
74 lines (53 loc) · 1.68 KB
/
SwordBehaviour.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 System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SwordBehaviour : MonoBehaviour {
private Animator anim;
public GameObject sword;
public bool isAttacking = false;
public static bool activate = false;
public AudioSource SwingSFX;
void Start () {
anim = GetComponent<Animator> ();
sword.GetComponent<Collider>().enabled = false;
}
void Update(){
if (activate == true) {
ActivateSword ();
}
//If left mouse button is clicked, (and Hero is not dead!) causes the Hero to swing his sword.
if (Input.GetMouseButtonDown (0) && CharacterMovement.isDead != true && sword.activeInHierarchy) {
anim.SetTrigger ("Basic_Attack");
SwingSFX.PlayDelayed (0.1f);
StartCoroutine("HandleSwordCollider");
}
}
IEnumerator HandleSwordCollider(){
//Turns on sword collider, allowing Hero to deal damage to enemy.
yield return new WaitForSeconds(0.4f);
Debug.Log ("Part One");
sword.GetComponent<Collider> ().enabled = true;
isAttacking = true;
//After .14 seconds (duration of animation), turn off sword collider
yield return new WaitForSeconds (0.1f);
Debug.Log ("Part Two");
sword.GetComponent<Collider> ().enabled = false;
isAttacking = false;
}
// Update is called once per frame
void OnTriggerEnter (Collider col){
if (col.gameObject.tag == "Enemy" && isAttacking ) {
col.gameObject.GetComponentInParent<SlimeBehaviour> ().TakeDamage ();
}
if (col.gameObject.tag == "Boss" && isAttacking) {
col.gameObject.GetComponentInParent<Boar> ().TakeDamage ();
}
}
void ActivateSword(){
sword.SetActive (true);
activate = false;
}
public static void EnableSword(){
activate = true;
}
}