I want the code to check if the object is alive, and if so, shoot it. I want to check and shoot all the time. The only problem is that checks can be done anytime you want, but shooting must have fire limits per second. I mean, you check the target all the time, but when you decide to shoot, the bullets will shoot one after the other with some delays. And also, when you realize that the target is dead, stop shooting at the same time.
void Update() { StartCoroutine(Shoot(currentTarget, 1f)); } IEnumerator Shoot(Collider currentTarget, float delayTime) { yield return new WaitForSeconds(delayTime); if (currentTarget != null) { ....... } }
This code starts to shoot, but without delays between shots.
David source share