I’m fairly new to using coroutines and I think I’m doing something wrong. I’ve implemented a dash mechanic and I’m trying to use a coroutine as a timer to keep the player from just spamming the dash button. However, it does not seem to be working. When I step through the code, it seems to be behaving exactly as I would expect… but when I play it isn’t. Hoping someone can quickly see what i’m doing wrong.
if(Input.GetKeyDown(KeyCode.LeftShift) && canDash && isOnGround)
{
if(Srend.flipX)
{
rb.AddForce((Vector2.right * -1 * dash) * Time.deltaTime * 70, ForceMode2D.Impulse);
}
if(!Srend.flipX)
{
rb.AddForce((Vector2.right * 1 * dash) * Time.deltaTime * 70, ForceMode2D.Impulse);
}
canDash = false;
StartCoroutine(DashTimer());
}
private IEnumerator DashTimer()
{
float timer = 0f;
while(timer < 5000)
{
timer += Time.deltaTime;
}
yield return canDash = true;
}