Hey. There is such a code -
if (Input.GetButtonDown("Reload") && !InRealod && Ammo < MaxAmmo) { StartCoroutine(ReloadCountdown()); } if (InRealod && Input.GetButtonDown("Fire") && Ammo != 0) { StopCoroutine(ReloadCountdown()); } IEnumerator ReloadCountdown() { while (Ammo < MaxAmmo) { InRealod = true; yield return new WaitForSeconds(ReloadTime); Ammo++; InRealod = false; } } But Korutina is not interrupted. All conditions are met. But she interrupts herself when Ammo == MaxAmmo. Even if you do this -
IEnumerator ReloadCountdown() { while (Ammo < MaxAmmo && !Input.GetButtonDown("Fire")) { InRealod = true; yield return new WaitForSeconds(ReloadTime); Ammo++; InRealod = false; } } nothing works. The idea is that charging cartridges into a weapon should go until the player presses the fire button (if Ammo! = 0). Why is it impossible to interrupt corutin?