-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDash_v1.cs
135 lines (115 loc) · 4.63 KB
/
Dash_v1.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Dash_v1 : MonoBehaviour
{
private Rigidbody2D rb;
public float dashSpeed;
private float dashTime;
public float startTime;
private int direction;
public int rightTotal = 0;
public float rightTime = 0;
public int leftTotal = 0;
public float leftTime = 0;
public Animator anim;
void Start()
{
rb = GetComponent<Rigidbody2D>();
dashTime = startTime;
anim = gameObject.GetComponent<Animator>();
}
void Update()
{
if (direction == 0)
{
if (Input.GetKeyDown(KeyCode.RightArrow))
{
rightTotal += 1;
// if the player enters the right key which is D then the count for how many times they pressed that will increase by 1
}
if ((rightTotal == 1) && (rightTime < 0.2))
rightTime += Time.deltaTime;
//if the count for how many times they pressed they left key is 1 and the time for long it has been since they pressed it is less than 0.2 seconds
// then the timer activates
if ((rightTotal == 1) && (rightTime >= 0.2))
{
rightTime = 0;
rightTotal = 0;
// if the count for left key pressed is still 1 and has been more than or equal to 0.2 seconds then count goes back to 0 so will the timer
anim.SetBool("goku_dash", false);
// this sets the double dash to false if the the above if statement is true
}
if ((rightTotal == 2) && (rightTime < 0.2))
{
direction = 2;
rightTotal = 0;
anim.SetBool("goku_dash", true);
//if left key is pressed twice and the time that has elapsed after the first count is still less than 0.2 seconds then the double dash animtion plays for player1
}
else if (Input.GetKeyDown(KeyCode.LeftArrow))
{
leftTotal += 1;
// if the player enters the right key which is D then the count for how many times they pressed that will increase by 1
}
if ((leftTotal == 1) && (leftTime < 0.2))
leftTime += Time.deltaTime;
//if the count for how many times they pressed they left key is 1 and the time for long it has been since they pressed it is less than 0.2 seconds
// then the timer activates
if ((leftTotal == 1) && (leftTime >= 0.2))
{
leftTime = 0;
leftTotal = 0;
// if the count for left key pressed is still 1 and has been more than or equal to 0.2 seconds then count goes back to 0 so will the timer
anim.SetBool("goku_dash", false);
// this sets the double dash to false if the the above if statement is true
}
if ((leftTotal == 2) && (leftTime < 0.2))
{
direction = 1;
leftTotal = 0;
anim.SetBool("goku_dash", true);
//if left key is pressed twice and the time that has elapsed after the first count is still less than 0.2 seconds then the double dash animtion plays for player1
}
/* else if (Input.GetKeyDown(KeyCode.W))
{
direction = 3;
}
else if (Input.GetKeyDown(KeyCode.S))
{
direction = 4;
}
*/
// the code below will handle how fast the speed is of the double dash
}
else
{
if (dashTime <= 0)
{
direction = 0;
dashTime = startTime;
rb.velocity = Vector2.zero;
}
else
{
dashTime -= Time.deltaTime;
if (direction == 1)
{
rb.velocity = Vector2.left * dashSpeed;
}
else if (direction == 2)
{
rb.velocity = Vector2.right * dashSpeed;
}
/* else if (direction == 3)
{
rb.velocity = Vector2.up * dashSpeed;
}
else if (direction == 2)
{
rb.velocity = Vector2.down * dashSpeed;
}*/
}
}
}
}