Code:
public float shooting_wait_time = 0.2f;
public int bullets;
private bool waiting = false;
void Update() {
if (Input.GetButtonDown("Fire1") && bullets != 0) {
if (!waiting) {
// Do shooting stuff
StartCoroutine(shoot_wait());
}
}
}
private IEnumerator shoot_wait() {
waiting = true;
yield return new WaitForSecondsRealtime(shooting_wait_time);
waiting = false;
}
As you can see I have a Coroutine that waits for 0.2 seconds... The problem is that sometimes it waits the right duration, but sometimes it does a short bursts of no sleep time! I've been looking it up for a long time but I have found no solutions for me.
I don't see what I'm doing wrong. Please help. Thank you in advance.
↧