Quantcast
Channel: Questions in topic: "gun"
Viewing all articles
Browse latest Browse all 592

WaitForSecond Corountine Sleep Time Varies

$
0
0
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.

Viewing all articles
Browse latest Browse all 592

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>