I was trying to implement dashing mechanic but every time I am trying to run this code my unity freezes. Any solutuions?
if(Input.GetKeyDown(KeyCode.LeftShift)){
StartCoroutine(DashCorutine());
}
}
private IEnumerator DashCorutine()
{
float starttime = Time.time;
while(starttime dashTime > Time.time){
Vector3 moveDerection= transform.forward*dashlength;
controller.Move(moveDerection *Time.deltaTime*dashSpeed);
}
yield return null;
}
}
CodePudding user response:
Add a yield inside the while loop.
CodePudding user response:
You need to add yield break inside while loop
private IEnumerator DashCorutine()
{
float startTime = Time.time;
while (startTime dashTime > Time.time)
{
Vector3 moveDirection = transform.forward * dashLength;
controller.Move(moveDirection * Time.deltaTime * dashSpeed);
yield break;
}
}
Also check out coding standards for better code quality.
And fix the typos.
