I am setting my player to have a cool down after running. My problem is:
After running in game, and the timer hits 0, my character is still set to the slow speed instead of reverting back to the original speed.
However, after another 15 seconds of holding down shift, my character reverts to normal, but now after the timer hits 0 will not slow down. Any help is appreciated! Thank you for your time.
public float walkSpeed = 6.0f;
public float walk;
public float runSpeed = 11.0f;
public float run;
public float crouchSpeed = 2.0f;
public float crouch;
public float slowSpeedWalk = 1.0f;
public float slowSpeedRun = 1.5f;
public float slowSpeedCrouch = .5f;
void Start() {
........
........
Init ();
}
public void Init(){
walk = walkSpeed;
run = runSpeed;
crouch = crouchSpeed;
endTime = runTimer;
}
void FixedUpdate(){
.......
.......
if ((Input.GetKey ("left shift") || Input.GetKey ("right shift"))) {
if (endTime <= 15) {
endTime -= Time.deltaTime;
}
if (endTime <= 0) {
runSpeed = slowSpeedRun;
walkSpeed = slowSpeedWalk;
crouchSpeed = slowSpeedCrouch;
endTime = 0;
StartCoroutine(Reset(6f));
}
} else {
if (endTime <= 15) {
endTime += Time.deltaTime;
}
if (endTime >= 15) {
endTime = 15;
}
}
}
........
........
IEnumerator Reset(float wait){
yield return new WaitForSeconds(wait);
Init ();
}