-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbroly_def.cs
71 lines (56 loc) · 2.29 KB
/
broly_def.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class broly_def : MonoBehaviour
{
public Animator anim;
bool def_b = false;
public CircleCollider2D def2_trigger;
public Collider2D def_trigger;
// both of the above triggers will be used to reference player2's colliders that will be activated when the defend button is activated
private float defTimer = 0;
private float defCd = 3;
// the 2 float variables above will be used to set the countdown of how long the def barrier lasts for
void Awake()
{
def2_trigger.enabled = false;
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
if (Input.GetKeyDown("/") && !def_b)
{
def_b = true;
def2_trigger.enabled = true;
// if the user has entered the guard key then defend will be true and so will the trigger
defTimer = defCd;// this will make the barrier last for 3 seconds
transform.gameObject.tag = ("def_2");
// this line of code will change the player2's tag from player2 to def_2 this way when player1 attacks it will detect the tag and cancel the damage being dealt
Debug.Log(tag);
print(tag);
// the 2 lines above will print to the console if the tag has changed
}
else if (Input.GetKeyDown("[4]") || (Input.GetKeyDown("[5]")))
{
def_b = false;
anim.SetBool("def_b", false);
}
if (def_b)
{
if (defTimer > 0)
{
defTimer -= Time.deltaTime;
// this will act as a timer for the guard barrier to go down
}
else
{
def_b = false;
def2_trigger.enabled = false;
transform.gameObject.tag = ("player2");
// if player 2 isnt defending anymore then teh tag will go back to player2 and player1 can return to doing damage
}
anim.SetBool("def_b", def_b);
// this line will play the aniimtion of the guard barrier depending on whether player 2 has entered the guard button
}
}
}