-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer1_atkV1.cs
128 lines (104 loc) · 3.76 KB
/
Player1_atkV1.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
using UnityEngine;
using System.Collections;
public class Player1_atkV1 : MonoBehaviour
{
bool punch = false;
bool kick = false;
// the above variables set punch and kick to false
private float atkTimer = 0;
private float atkCd = 0.1f;
// the float variables are used for the delays between attacks
public Collider2D player1_triggerV1; // this references the collider that is the child of the gameObject which is the character
public Animator animator;
public int punchTotal = 0;
public float punchTimer = 0;
public float punchCd = 2;
public int kickTotal = 0;
public float kickTimer = 0;
public float kickCd = 0;
void Awake()
{
animator = gameObject.GetComponent<Animator>();
player1_triggerV1.enabled = false;// this sets the trigger in the begging of the game to false
}
void Update()
{
if (Input.GetKeyDown(",") && !punch)
{
punch = true;
atkTimer = atkCd;
// this checks if the player enters the button punch button which is i, if so then punch becomes true
player1_triggerV1.enabled = true;
// the trigger then also becomes true
punchTotal += 1;
}
if (punchTotal == 4)
{
punchTimer = punchCd;
punchTotal = 0;
}
if (punchTimer > 0)
{
punchTimer -= Time.deltaTime;
punch = false;
player1_triggerV1.enabled = false;
punchTotal = 0;
}
/* else
{
punch = true;
player1_trigger.enabled = true;
}*/
if (punch)
{
if (atkTimer > 0)
{
atkTimer -= Time.deltaTime;// if the atk timer is bigger then 0 then this line will decrease the time by delta time which works as a real timer
}
else
{
punch = false;
player1_triggerV1.enabled = false;
// if player is not usinf the punch key button then punching becomes false and the trigger will also be false
}
}
animator.SetBool("punch", punch);
// this will set the punch animation in the animator of player 1 to true or false depending on the two if statements above
if (Input.GetKeyDown(".") && !kick)
{
kick = true;
atkTimer = atkCd;
// this checks if the player enters the button punch button which is i, if so then punch becomes true
player1_triggerV1.enabled = true;
// the trigger then also becomes true
kickTotal += 1;
}
if (kickTotal == 4)
{
kickTimer = kickCd;
kickTotal = 0;
}
if (kickTimer > 0)
{
kickTimer -= Time.deltaTime;
kick = false;
player1_triggerV1.enabled = false;
kickTotal = 0;
}
if (kick)
{
if (atkTimer > 0)
{
atkTimer -= Time.deltaTime;// if the atk timer is bigger then 0 then this line will decrease the time by delta time which works as a real timer
}
else
{
kick = false;
player1_triggerV1.enabled = false;
// if player is not usinf the punch key button then punching becomes false and the trigger will also be false
}
}
animator.SetBool("kick", kick);
// this will set the punch animation in the animator of player 1 to true or false depending on the two if statements above
}
}