0

So this script should switch through magazines, not fill a magazine. What happens is with the first reload, even tho' the animation happens and everything. The magazine doesn't change until after you shoot and then reload. Reloading again will switch between 2 out of 4 magazines even if the 2 are empty (which is expected because it can switch if there is a magazine with bullets).

Here is the code:

if (Input.GetAxis ("Reload") > 0 && reloading == false && pressedReload == false && runningAutomatic == false && mags[currMag] < magazineSize && animator.GetCurrentAnimatorStateInfo (0).IsName (shootAnim.name) == false) {
    for (int i = 0; i < mags.Length; i++) {

        if (mags [i] > 0) {
            Reload (currMag + 1);
            animator.SetFloat ("ReloadSpeed", reloadSpeed);
            animator.Play (reloadAnim.name);
            pressedReload = true;
            reloading = true;
        }
    }
}
reloading = animator.GetCurrentAnimatorStateInfo (0).IsName (reloadAnim.name);
    if (reloading)
        pressedReload = false;

...

void Reload (int currentMagazine) {

    if (currentMagazine == mags.Length)
    currentMagazine = 0;
    currMag = currentMagazine;
}
  • Just as a side note, I think you've forgotten to `break` out of your for loop after identifying a magazine you can reload with - in its current state, it's going to execute the conditional code for every non-empty magazine, even if one has already been selected to reload with. – Serlite Jan 09 '17 at 01:28
  • 1
    haha thank you, that fixed it. I somehow forgot that a for loop is played completely in one frame :P –  Jan 09 '17 at 01:31

1 Answers1

0

Just forgot to break; the for loop... Thanks to Serlite :D