My player can dash when the player presses left shift, but I can’t get the double tap on the left and right arrow keys to work
Here’s the code (Brought it down to the dash elements to make it easier) Thanks
public float dashDistance = 10f;
bool isDashing;
float doubleTapTime;
KeyCode lastKeyCode;
float mx;
[Header("Dashing")]
[SerializeField] private float m_JumpForce = 400f;
public bool canDash = true;
public float dashingTime;
public float dashSpeed;
public float dashJumpIncrease;
public float timeBtwDashes;
void FixedUpdate()
{
// if(canMove)
//Dashing left
if (Input.GetKeyDown(KeyCode.LeftArrow))
{
if (doubleTapTime > Time.time && lastKeyCode == KeyCode.LeftArrow){
DashAbility();
}
} else {
doubleTapTime = Time.time + 0.3f;
}
lastKeyCode = KeyCode.LeftArrow;
//Dashing right
if (Input.GetKeyDown(KeyCode.RightArrow))
{
if (doubleTapTime > Time.time && lastKeyCode == KeyCode.RightArrow){
DashAbility();
}
} else {
doubleTapTime = Time.time + 0.3f;
}
lastKeyCode = KeyCode.RightArrow;
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
DashAbility();
}
}
void DashAbility()
{
if(canDash)
{
StartCoroutine(Dash());
}
}
IEnumerator Dash()
{
canDash = false;
runSpeed = dashSpeed;
m_JumpForce = dashJumpIncrease;
yield return new WaitForSeconds(dashingTime);
runSpeed = 50f;
m_JumpForce = 800f;
yield return new WaitForSeconds(timeBtwDashes);
canDash = true;
}