Sprint like Dark Souls ?

Updated on March 12, 2017 in Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on March 12, 2017


private int sprint = 100;

public int sprintTime;

public bool sprintsBool;
void Update() {
if (Input.GetKey(KeyCode.I)) {

sprintTime --;

sprintsBool = true;

Debug.Log(" run ");

}

else {

sprintsBool = false;

}

if (sprintsBool == false) {

StartCoroutine("wait_sprit");
}

if (sprintTime >= sprint) {

sprintTime = sprint;

}

if (sprintTime <= 0) {

sprintTime = 0;

}
} // end update
IEnumerator wait_sprit() {

yield return new WaitForSeconds(2);

sprintTime ++;
}


my script is about count up when player is walking. but when i press “I” button, it counts down. the problem is when i press “I” button it not counts down immediately ! it continue counting for 1 or 2 seconds then count down ! How to fix this ?

  • Liked by
Reply