-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer2_atk.cs
149 lines (116 loc) · 3.35 KB
/
Player2_atk.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player2_atk : MonoBehaviour
{
bool punch_b = false;
bool kick_b = false;
bool SA = false;
private float atkTimer = 0;
private float atkCd = 0.3f;
public Collider2D player2_trigger;
public Collider2D player2_triggerSA;
public Transform SA_firepoint;
public GameObject SAPrefab;
public Animator animator;
public int SAtotal = 0;
public float SAtimer = 0;
public float SAcd = 0;
void Awake()
{
animator = gameObject.GetComponent<Animator>();
player2_trigger.enabled = false;
}
void Update()
{
if (Input.GetKeyDown(",") && !punch_b)
{
punch_b = true;
atkTimer = atkCd;
player2_trigger.enabled = true;
}
if (punch_b)
{
if (atkTimer > 0)
{
atkTimer -= Time.deltaTime;
}
else
{
punch_b = false;
player2_trigger.enabled = false;
}
}
animator.SetBool("punch_b", punch_b);
if (Input.GetKeyDown(".") && !kick_b)
{
kick_b = true;
atkTimer = atkCd;
player2_trigger.enabled = true;
}
if (kick_b)
{
if (atkTimer > 0)
{
atkTimer -= Time.deltaTime;
}
else
{
kick_b = false;
player2_trigger.enabled = false;
}
}
animator.SetBool("kick_b", kick_b);
if (Input.GetKeyDown("m") && !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());
Shoot();
// the trigger then also becomes true
SAtotal += 1;
}
IEnumerator SAtrigger()
{
yield return new WaitForSeconds(0.45f);
player2_triggerSA.enabled = true;
}
if (SAtotal == 1)
{
SAtimer = SAcd;
SAtotal = 0;
}
if (SAtimer > 0)
{
SAtimer -= Time.deltaTime;
SA = false;
player2_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;
player2_triggerSA.enabled = false;
// if player is not usinf the punch key button then punching becomes false and the trigger will also be false
}
}
animator.SetBool("brolySA", SA);
}
void Shoot()
{
Instantiate(SAPrefab, SA_firepoint.position, SA_firepoint.rotation);
}
}