void Update() { switch (dashState) { case DashState.Dashing: //show the player dashing animation animator.SetBool("is_dashing", true); dashTimer += Time.deltaTime * 5; if (dashTimer >= maxDash) { //stop the player dashing animation animator.SetBool("is_dashing", false); //changing player state playerStateScript.SetIsDashing(false); dashTimer = maxDash; //r_body.velocity = savedVelocity; dashState = DashState.Cooldown; } break; case DashState.Cooldown: dashTimer -= Time.deltaTime; if (dashTimer <= 0) { dashTimer = 0; dashState = DashState.Ready; } break; case DashState.Ready: //if dash button is pressed, set velocity... if (dashInputScript.GetDashButton()) { if (!playerStateScript.GetHasPearl() && !playerStateScript.GetIsHit()) { // savedVelocity = r_body.velocity; //find the angle to dash based on the angle player is facing Vector3 dir; if (movingScript.GetFacingRight()) { dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 90f, Vector3.forward) * Vector3.up; } else { dir = Quaternion.AngleAxis(playerStateScript.GetFacingAngle() - 270f, Vector3.forward) * Vector3.up; } //apply force to the player in that direction GetComponent <Rigidbody2D>().AddForce(dir * dashVelocity); //adding the dash burst to the player velocity //r_body.AddForce(new Vector2(dashVelocity * 1f, dashVelocity * 1f)); //changing player state playerStateScript.SetIsDashing(true); dashState = DashState.Dashing; //splashSound.Play(); soundPlayer.PlayClip(dashSound, 1.0f); } } break; } }