-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMovement.cs
65 lines (52 loc) · 1.53 KB
/
Movement.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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Movement : MonoBehaviour
{
public Rigidbody2D myRigidbody;
public Animator animator;
public float moveSpeed;
private Vector2 movement;
// Dash variables
private float activeMoveSpeed;
public float dashSpeed;
public float dashLength = .5f, dashCooldown = 1f;
private float dashCounter;
private float dashCoolCounter;
void Start()
{
activeMoveSpeed = moveSpeed;
}
void Update()
{
movement.x = Input.GetAxisRaw("Horizontal");
movement.y = Input.GetAxisRaw("Vertical");
animator.SetFloat("Move", movement.x);
animator.SetFloat("Speed", movement.sqrMagnitude);
if (Input.GetKeyDown(KeyCode.C))
{
if (dashCoolCounter <= 0 && dashCounter <= 0)
{
activeMoveSpeed = dashSpeed;
dashCounter = dashLength;
}
}
if (dashCounter > 0)
{
dashCounter -= Time.deltaTime;
if (dashCounter <= 0)
{
activeMoveSpeed = moveSpeed;
dashCoolCounter = dashCooldown;
}
}
if (dashCoolCounter > 0)
{
dashCoolCounter -= Time.deltaTime;
}
}
private void FixedUpdate()
{
myRigidbody.MovePosition(myRigidbody.position + movement * activeMoveSpeed * Time.fixedDeltaTime);
}
}