Hello, I am working on the beginnings of an ammo script. I am using an if statement to check if the ammo in the clip is < 1. When that happens I StartCoroutine. In this IEnumerator, I reload clip, subtract from total ammo and yield for seconds. However, the yield never seems to work.
It seems as though it returns right back to the update() once those variables are calculated but never waitsforseconds.
//Here are parts of my code
public class PistolScript : MonoBehaviour {
public PlayerInventory inventoryScript;
public float maxClipAmount;
public float ammoInClip;
public float currentAmmo;
public float reloadTime;
void FixedUpdate () {
if(ammoInClip < 1){
StartCoroutine(LoadGun ());
}
}
IEnumerator LoadGun(){
ammoInClip = maxClipAmount;
currentAmmo = currentAmmo - ammoInClip;
yield return new WaitForSeconds(2);
}
//I've also arranged the IEnumerator differently, if that does anything at all.
IEnumerator LoadGun(){
yield return new WaitForSeconds(2);
ammoInClip = maxClipAmount;
currentAmmo = currentAmmo - ammoInClip;
}
I also want to replace the waitforseconds float with the float reloadTime. I assume it will work when I find out this problem.
Thankyou for any help pointing out my flaw.