-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer1Atk.cs
199 lines (159 loc) · 5.62 KB
/
Player1Atk.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
using UnityEngine;
using System.Collections;
public class Player1Atk : MonoBehaviour{
bool punch = false;
bool kick = false;
bool SA = 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_trigger; // this references the collider that is the child of the gameObject which is the character
public Collider2D player1_triggerSA;
public Animator animator;
public int punchTotal = 0;
public float punchTimer = 0;
public float punchCd = 0;
public int kickTotal = 0;
public float kickTimer = 0;
public float kickCd = 0;
public int SAtotal = 0;
public float SAtimer = 0;
public float SAcd = 0;
void Start()
{
}
void Awake()
{
animator = gameObject.GetComponent<Animator>();
player1_trigger.enabled = false;// this sets the trigger in the begging of the game to false
player1_triggerSA.enabled = false;
}
void Update()
{
if (Input.GetKeyDown("i") && !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_trigger.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_trigger.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_trigger.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("o") && !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_trigger.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_trigger.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_trigger.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
if (Input.GetKeyDown("l") && !SA)
{
SA = true;
Debug.Log("sa");
atkTimer = atkCd;
// this checks if the player enters the button punch button which is i, if so then punch becomes true
StartCoroutine(SAtrigger());
// the trigger then also becomes true
SAtotal += 1;
}
IEnumerator SAtrigger()
{
yield return new WaitForSeconds(0.45f);
player1_triggerSA.enabled = true;
}
if (SAtotal == 1)
{
SAtimer = SAcd;
SAtotal = 0;
}
if (SAtimer > 0)
{
SAtimer -= Time.deltaTime;
SA = false;
player1_triggerSA.enabled = false;
SAtotal = 0;
}
/* else
{
SA = true;
player1_triggerSA.enabled = true;
}*/
if (SA)
{
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
{
SA = false;
player1_triggerSA.enabled = false;
// if player is not using the super attack button then SA becomes false and the trigger will also be false
}
}
animator.SetBool("SA1", SA);
// this will set the punch animation in the animator of player 1 to true or false depending on the two if statements above
}
}