I have followed this tutorial Unity Tutorial: Dashing like in Celeste & Hollow Knight - YouTube and it’s saying
Here’s my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private Rigidbody2D rb;
private BoxCollider2D bc;
private static bool isRunning;
private static bool isMoving;
private static bool isDashing;
private static bool isOnWall;
private static bool cooldown;
private static bool jumpCooldown;
private float time = 2;
private float dashingspeed = 14;
private Vector2 dashingDir;
// Start is called before the first frame update
private void Start()
{
rb = GetComponent<Rigidbody2D>();
bc = GetComponent<BoxCollider2D>();
cooldown = false;
}
// Update is called once per frame
private void Update()
{
float dirX = Input.GetAxisRaw("Horizontal");
rb.velocity = new Vector2(dirX * 4f, rb.velocity.y);
isMoving = true;
float dirY = Input.GetAxisRaw("Vertical");
if (Input.GetKey("left ctrl"))
isRunning = true;
else
{
isRunning = false;
}
if (Input.GetKeyDown("left shift"))
isDashing = true;
else
{
isDashing = false;
}
if (Input.GetButtonDown("Jump"))
{
rb.velocity = new Vector2(rb.velocity.x, 8f);
}
if (isRunning == true && isMoving == true)
{
rb.velocity = new Vector2(dirX * 6f, rb.velocity.y);
}
if (isDashing == true && cooldown == false)
{
cooldown = true;
dashingDir = new Vector2(Input.GetAxisRaw("Horizontal"), Input.GetAxisRaw("Vertical"));
isDashing = false;
if (dashingDir == new Vector2(0,0))
{
dashingDir = new Vector2(transform.localScale.x, 0);
}
StartCoroutine(StopDashing());
}
if (isDashing == true)
{
rb.velocity = dashingDir.normalized * dashingspeed;
return;
}
if (IsGrounded())
{
cooldown = false;
}
IEnumerator StopDashing();
{
yield return new WaitForSeconds(time);
cooldown = false;
}
}
}