while loop running twice the normal amount

why is my while loop running incorrect ?
it basicly gets triggered twice the amount it should be running.
the “ammo +” gets triggered twice instead of once. also the second while loop doesnt set the animtionsclip normalized time to 0.

            if (reloadonce)
            {
              
                while (currentammo != clipSize && ammo > 0 )
                {
                    //Debug.Log(lastreloadtime);
                  
                  
                    if (lastreloadtime != 0)
                    {
                      
                        myanimation[reloadonceAnim.name].normalizedTime = lastreloadtime;
                        myanimation.Play(reloadonceAnim.name);
                        myAudioSource.time = myaudioLastTime;
                        myAudioSource.clip = reloadonceSound;
                        myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                        myAudioSource.Play();
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f * lastreloadtime);

                        currentammo += 1;
                        ammo -= 1;
                        Debug.Log("isdoingtimedreload");
                        inventory.UpdateCurrentWeaponAmmo(ammo);
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f * lastreloadtime);
                        lastreloadtime = 0f;
                        myaudioLastTime = 0f;
                        //Debug.Log(lastreloadtime);
                        myAudioSource.time = myaudioLastTime;
                        myanimation[reloadonceAnim.name].normalizedTime = lastreloadtime;
                        myanimation.Stop();

                    }
                    else
                    {
                      
                        myanimation.Play(reloadonceAnim.name);
                        Debug.Log(lastreloadtime);
                        myAudioSource.clip = reloadonceSound;
                        myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                        myAudioSource.Play();
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);
                        Debug.Log("isdoingnormalreload");
                        currentammo += 1;
                        ammo -= 1;

                        inventory.UpdateCurrentWeaponAmmo(ammo);
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);
                        myanimation.Stop();

                    }


                }
               
                myanimation.Play(reloadlastAnim.name);
              
                yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length );
                reloadlast = false;
              
                myanimation[pumpAnim.name].normalizedTime = 0;
              
                myanimation.Play(pumpAnim.name);
                if (!didejectshells)
                {
                    StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay ));
                }
                myAudioSource.time = myaudioLastTime;
                myAudioSource.clip = pumpSound;
                myAudioSource.Play();
                yield return new WaitForSeconds(myanimation[pumpAnim.name].length );
                ispumping = false;
                reloadonce = false;
                isreloading = false;
                canaim = true;

                canfire = true;


            }

this is the normal reload wich runs fine.
its basicly the exact while loop without an if statement

while (currentammo != clipSize && ammo > 0)
            {
                myAudioSource.time = 0f;

                myanimation.Play(reloadonceAnim.name);
                myAudioSource.clip = reloadonceSound;
                myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                myAudioSource.Play();


                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);

                currentammo += 1;
                ammo -= 1;

                inventory.UpdateCurrentWeaponAmmo(ammo);

                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);

                myanimation.Stop();

            }
            myanimation.Play(reloadlastAnim.name);

            yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length);
            StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay));
            myanimation.Play(pumpAnim.name);
            myAudioSource.clip = pumpSound;
            myAudioSource.Play();
            yield return new WaitForSeconds(myanimation[pumpAnim.name].length);
            isreloading = false;
            canaim = true;
           
            canfire = true;

How and where are you starting this coroutine?
Are you making sure another copy of the coroutine is not already running when you start it?

heres the full script >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ShotgunShooter : MonoBehaviour {

    //variables
    public Transform player;

    public Vector3 normalposition;
    public Vector3 aimposition;   
    public Vector3 retractPos;

    public float aimFOV = 45f;
    public float normalFOV = 75f;
    public float runFOV = 85f;





    public AnimationClip fireAnim;


    public AudioClip fireSound;
    public AudioSource fireAudioSource;

    public AnimationClip pumpAnim;
    public AnimationClip toreloadAnim;
    public AnimationClip reloadonceAnim;
    public AnimationClip reloadlastAnim;

    private bool toreload = false;
    private bool reloadonce = false;
   
    private bool reloadlast = false;
    private bool reloadA = false;
    private bool reloadB = false;
    private bool ispumping = false;

    public AnimationClip readyAnim;
    public AnimationClip hideAnim;
    public AnimationClip meleeAnim;

    public AnimationClip ambientAnim;
    public AudioSource myAudioSource;
    public AudioClip emptySound;
    public AudioClip readySound;
    public AudioClip meleeSound;
   
    public AudioClip pumpSound;
    public AudioClip reloadonceSound;

    private float lastreloadtime = 0f;

    private float myaudioLastTime = 0f;

    public float shellejectdelay;
    public GameObject shell;
    public Transform shellPos;
    private bool didejectshells = false;

    public Transform particlesmuzzle;

    public int projectilecount = 1;
    private float inaccuracy = 0.02f;
    public float spreadNormal = 0.08f;
    public float spreadAim = 0.02f;
    public float force  = 500f;
    public float damage = 50f;
    public float range = 100f;

    private float recoil;
    public float recoilNormal = 2f;
    public float recoilaim = 0.5f;
    public int weaponammo;
    public int ammo = 200;
    public int currentammo= 20;
    public int clipSize = 20;


   

    public float runXrotation = 20f;
    public float runYrotation = 0f;
    public Vector3 runposition = Vector3.zero;



    //private
    private float nextField;
   

    private Vector3 wantedrotation;
    private bool canaim = true;
    private bool isaiming = false;
    private bool canfire = true;
    private bool canreload = true;
    private bool retract = false;   
    private bool isreloading  = false;

    private float nextambient = 2f;
    public Transform rayfirer;
    public Transform grenadethrower;
    public Transform syringeshooter;
    public Transform weaponroot;
    //scriptreference
    raycastfire weaponfirer;
    playercontroller playercontrol ;
    weaponselector inventory;
    camerarotate cameracontroller;
    Animation myanimation;
    Weaponbob weaponbobber;
    void Awake()
    {
        weaponfirer = rayfirer.GetComponent<raycastfire>();
        playercontrol = player.GetComponent<playercontroller>();
        myanimation = GetComponent<Animation>();
        cameracontroller = rayfirer.GetComponent<camerarotate>();
        weaponbobber = weaponroot.GetComponent<Weaponbob>();
        inventory = player.GetComponent<weaponselector>();
    }
    void Start()
    {
        clipSize=currentammo;


        nextField = normalFOV ;
       
        myanimation.Stop();
        onstart();
    }

    void onstart()
    {
        StartCoroutine(waitforinput());
        retract = false;
        weaponbobber.isaiming = false;
       
        ParticleSystem[] particleSystems;
        particleSystems = particlesmuzzle.GetComponentsInChildren<ParticleSystem>();
        foreach (ParticleSystem particle in particleSystems)
        {
            particle.Stop();
        }
        myAudioSource.Stop();
        fireAudioSource.Stop();
       
       
        weaponfirer.inaccuracy = inaccuracy;
        weaponfirer.damage = damage;
        weaponfirer.range = range;
        weaponfirer.force = force;
        weaponfirer.projectilecount = projectilecount;
        weaponfirer.projectilecount = projectilecount;
        ammo = inventory.WeaponsAmmo[weaponammo];
        inventory.UpdateCurrentWeaponAmmo(ammo);
        inventory.showAIM(false);

        myanimation.Stop();
        if (isreloading)
        {
            isreloading = !isreloading;
            reload();
        }
        else
        {


            myaudioLastTime = 0f;
            myAudioSource.time = myaudioLastTime;
            myAudioSource.clip = readySound;
            myAudioSource.loop = false;
            myAudioSource.volume = 1;
            myAudioSource.Play();
            myanimation.Play(readyAnim.name);
        }

    }
    IEnumerator waitforinput()
    {
        inventory.showAIM(false);
        canaim = false;
        yield return new WaitForSeconds(myanimation[readyAnim.name].length);
        canaim = true;
        canfire = true;
        inventory.showAIM(true);
    }
    void Update ()
    {
        if (!myanimation.isPlaying || myanimation.IsPlaying(ambientAnim.name))
        {
            if (!isreloading ) {
                if (isaiming)
                    inventory.showAIM (false);
                else
                    inventory.showAIM (true);
                if ((Input.GetButton ("Fire1") || Input.GetAxis ("Fire1") > 0.1) && currentammo > 0 && canfire && !isreloading )
                {

                    fire ();


                }
                else if (Input.GetButton("ThrowGrenade") && inventory.grenade > 0 && !isaiming)
                {

                    if(Time.timeSinceLevelLoad>(inventory.lastGrenade+1))
                    {
                        inventory.lastGrenade=Time.timeSinceLevelLoad;           
                        StartCoroutine(setThrowGrenade());
                    }


                }
                else if (Input.GetButton("syringeshot") && inventory.syringe > 0 && playercontrol.hitpoints < 100)
                {

                    if (Time.timeSinceLevelLoad > (inventory.lastsyringe + 1))
                    {
                        inventory.lastsyringe = Time.timeSinceLevelLoad;
                        StartCoroutine(setsyringeshot());
                    }


                }
                else if (Input.GetButton("Melee"))
                {

                    StartCoroutine(setMelee (.12f));


                }
                else if(Input.GetButton("Reload") ){
                    //Debug.Log("RELOAD");
                    if (currentammo <= clipSize && ammo > 0)
                    {

                        reload();
                    }
                }
                else if (Time.time > nextambient && !myanimation.IsPlaying(ambientAnim.name) && !isaiming)
                {

                    nextambient = Time.time + Random.Range (5f, 15f);
                    myanimation.Play(ambientAnim.name);

                }
                else if (currentammo  <= 0 )
                {   

                    if (ammo <= 0)
                    {
                        canfire = false;
                        canreload = false;
                        if ((Input.GetButton("Fire1") || Input.GetAxis ("Fire1")>0.1) && !myAudioSource.isPlaying)
                        {
                            if (!myAudioSource.isPlaying)
                            {
                                myAudioSource.PlayOneShot(emptySound);
                            }
                        }

                    }
                    else
                    {
                        reload();
                    }
                }


            }
            else
            {
                inventory.showAIM (false);
            }



        }

        float step = 2 * Time.deltaTime;

        float newField = Mathf.Lerp(Camera.main.fieldOfView, nextField, Time.deltaTime * 2);
       
        Camera.main.fieldOfView = newField;
       
        inventory.currentammo = currentammo;

        if (retract)
        {
            canfire = false;
            canaim = false;
            transform.localPosition = Vector3.MoveTowards(transform.localPosition, retractPos, step *3f);
            cameracontroller.isaiming = false;
            nextField = normalFOV;
        }

        if (retract)
        {
            canfire = false;
            canaim = false;
            transform.localPosition = Vector3.MoveTowards(transform.localPosition, retractPos, step * 3f);
            cameracontroller.isaiming = false;
            weaponbobber.isaiming = false;
            nextField = normalFOV;
        }

        else if (playercontrol.running && playercontrol.GetComponent<CharacterController>().isGrounded)
        {
            canfire = false;
            transform.localPosition = Vector3.MoveTowards(transform.localPosition, runposition, step);
            wantedrotation = new Vector3(runXrotation, runYrotation, 0f);
            inventory.showAIM(false);
            weaponbobber.isaiming = false;
            cameracontroller.isaiming = false;
            nextField = runFOV;

        }
        else
        {
            canfire = true;
            wantedrotation = Vector3.zero;
            if (((Input.GetButton("Aim") || Input.GetAxis("Aim") > 0.1)) && canaim && !playercontrol.running)
            {
                isaiming = true;
                weaponbobber.isaiming = true;
                inaccuracy = spreadAim;
                transform.localPosition = Vector3.MoveTowards(transform.localPosition, aimposition, step);
                inventory.showAIM(false);
                nextField = aimFOV;
                recoil = recoilaim;
                cameracontroller.isaiming = true;
            }
            else
            {
                inventory.showAIM(true);
                isaiming = false;
                weaponbobber.isaiming = false;
                inaccuracy = spreadNormal;
                transform.localPosition = Vector3.MoveTowards(transform.localPosition, normalposition, step);
                cameracontroller.isaiming = false;
                nextField = normalFOV;
                recoil = recoilNormal;


            }

        }
        weaponfirer.inaccuracy = inaccuracy;
        transform.localRotation = Quaternion.Lerp(transform.localRotation,Quaternion.Euler(wantedrotation),step * 3f);
    }

    void reload()
    {
        if (canreload && !isreloading)
        {
            myAudioSource.pitch = 1f;
            if (currentammo > 0 && !reloadA)
            {
                StartCoroutine(SetReloadB());
            }
            else
            {
                StartCoroutine(SetReloadA());
               
            }
        }
    }
    void fire()
    {
       
           
        float randomZ = Random.Range (-0.05f,-0.01f);
        transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y ,transform.localPosition.z + randomZ);

        StartCoroutine(setfire());


    }

    void doNormal()
    {
        onstart();
    }

    void flashthemuzzle()
    {
        ParticleSystem[] particleSystems;
        particleSystems = particlesmuzzle.GetComponentsInChildren<ParticleSystem>();
        foreach (ParticleSystem particle in particleSystems)
        {
            particle.Play();
        }



    }
    IEnumerator ejectshell(float waitTime)
    {
        didejectshells = false;
        yield return new WaitForSeconds(waitTime);
        GameObject shellInstance;
        shellInstance = Instantiate(shell, shellPos.transform.position,shellPos.transform.rotation) as GameObject;
        didejectshells = true;
        yield return null;
        shellInstance.GetComponent<Rigidbody>().AddRelativeForce(120,70,0);
        shellInstance.GetComponent<Rigidbody>().AddRelativeTorque(500,20,800);
        shellInstance.transform.localRotation = transform.localRotation * Quaternion.Euler(0,Random.Range(-90f,90f),0);
       
    }
    IEnumerator SetReloadA()
    {
        myanimation.Stop();
        myAudioSource.time = myaudioLastTime;
        //reload first
        canfire = false;
        isreloading = true;
        canaim = false;
        reloadA = true;
       
        if (lastreloadtime != 0)
        {
            // do animtime calculations
            if (toreload)
            {
                myanimation[toreloadAnim.name].normalizedTime = lastreloadtime;
                myanimation.Play(toreloadAnim.name);
                yield return new WaitForSeconds(myanimation[toreloadAnim.name].length * lastreloadtime);
                toreload = false;
                lastreloadtime = 0f;
                myAudioSource.time = 0;
                while (currentammo != clipSize && ammo > 0)
                {
                   

                    myanimation.Play(reloadonceAnim.name);
                    myAudioSource.clip = reloadonceSound;
                    myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                    myAudioSource.Play();


                    yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);

                    currentammo += 1;
                    ammo -= 1;

                    inventory.UpdateCurrentWeaponAmmo(ammo);

                    yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);

                    myanimation.Stop();

                }
                myanimation.Play(reloadlastAnim.name);

                yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length);
                StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay));
                myanimation.Play(pumpAnim.name);
                myAudioSource.clip = pumpSound;
                myAudioSource.Play();
                yield return new WaitForSeconds(myanimation[pumpAnim.name].length);
                isreloading = false;
                canaim = true;

                canfire = true;

            }

            if (reloadonce)
            {
               
                while (currentammo != clipSize && ammo > 0 )
                {
                    //Debug.Log(lastreloadtime);
                   
                   
                    if (lastreloadtime != 0)
                    {
                       
                        myanimation[reloadonceAnim.name].normalizedTime = lastreloadtime;
                        myanimation.Play(reloadonceAnim.name);
                        myAudioSource.time = myaudioLastTime;
                        myAudioSource.clip = reloadonceSound;
                        myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                        myAudioSource.Play();
                        Debug.Log(lastreloadtime);
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f * lastreloadtime);

                        currentammo += 1;
                        ammo -= 1;
                        Debug.Log("isdoingtimedreload");
                        inventory.UpdateCurrentWeaponAmmo(ammo);
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f * lastreloadtime);

                        lastreloadtime = 0f;
                        myaudioLastTime = 0f;
                       
                        myAudioSource.time = myaudioLastTime;
                        myanimation[reloadonceAnim.name].normalizedTime = lastreloadtime;
                        myanimation.Stop();

                    }
                    else
                    {
                        Debug.Log(myanimation[reloadonceAnim.name].normalizedTime);
                        myanimation.Play(reloadonceAnim.name);
                       
                        myAudioSource.clip = reloadonceSound;
                        myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                        myAudioSource.Play();
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);
                        Debug.Log("isdoingnormalreload");
                        currentammo += 1;
                        ammo -= 1;

                        inventory.UpdateCurrentWeaponAmmo(ammo);
                        yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);
                        myanimation.Stop();

                    }


                }
                myanimation[reloadlastAnim.name].normalizedTime = 0;
                myanimation.Play(reloadlastAnim.name);
               
                yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length );
                reloadlast = false;
               
                myanimation[pumpAnim.name].normalizedTime = 0;
               
                myanimation.Play(pumpAnim.name);
                if (!didejectshells)
                {
                    StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay ));
                }
                myAudioSource.time = myaudioLastTime;
                myAudioSource.clip = pumpSound;
                myAudioSource.Play();
                yield return new WaitForSeconds(myanimation[pumpAnim.name].length );
                ispumping = false;
                reloadonce = false;
                isreloading = false;
                canaim = true;

                canfire = true;


            }



            if (reloadlast )
            {
                myanimation[reloadlastAnim.name].normalizedTime = lastreloadtime;
                myanimation.Play(reloadlastAnim.name);

                yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length * lastreloadtime);
                reloadlast = false;
                lastreloadtime = 0f;
                myaudioLastTime = 0f;
                myAudioSource.time = myaudioLastTime;
                myanimation[pumpAnim.name].normalizedTime = lastreloadtime;
                myanimation.Play(pumpAnim.name);
                if (!didejectshells)
                {
                    StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay ));
                }

                myAudioSource.clip = pumpSound;
                myAudioSource.Play();
                yield return new WaitForSeconds(myanimation[pumpAnim.name].length );
                ispumping = false;
               
                isreloading = false;
                canaim = true;

                canfire = true;
            }
            if (ispumping)
            {
                myAudioSource.time = myaudioLastTime;
                myAudioSource.clip = pumpSound;
                myAudioSource.Play();
                myanimation[pumpAnim.name].normalizedTime = lastreloadtime;
                myanimation.Play(pumpAnim.name);
                if (!didejectshells)
                {
                    StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay * lastreloadtime));
                }
               
                yield return new WaitForSeconds(myanimation[pumpAnim.name].length * lastreloadtime);
                ispumping = false;
                lastreloadtime = 0f;
                myaudioLastTime = 0f;
                myAudioSource.time = myaudioLastTime;
                isreloading = false;
                canaim = true;
               
                canfire = true;
            }
        }

       
        else
        {
            myanimation.Play(toreloadAnim.name);
            yield return new WaitForSeconds(myanimation[toreloadAnim.name].length);



            while (currentammo != clipSize && ammo > 0)
            {
                myAudioSource.time = 0f;

                myanimation.Play(reloadonceAnim.name);
                myAudioSource.clip = reloadonceSound;
                myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                myAudioSource.Play();


                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);

                currentammo += 1;
                ammo -= 1;

                inventory.UpdateCurrentWeaponAmmo(ammo);

                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);

                myanimation.Stop();

            }
            myanimation.Play(reloadlastAnim.name);

            yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length);
            StartCoroutine(ejectshell(myanimation[pumpAnim.name].length * shellejectdelay));
            myanimation.Play(pumpAnim.name);
            myAudioSource.clip = pumpSound;
            myAudioSource.Play();
            yield return new WaitForSeconds(myanimation[pumpAnim.name].length);
            isreloading = false;
            canaim = true;
           
            canfire = true;

        }
    }
    IEnumerator SetReloadB()
    {
        reloadA = false;
        myanimation.Stop();
        myAudioSource.time = myaudioLastTime;
        //reload first
        canfire = false;
        isreloading = true;
        canaim = false;
        myAudioSource.time = myaudioLastTime;
        if (lastreloadtime != 0)
        {
            // do animtime calculations

        }
        else
        {
            myanimation.Play(toreloadAnim.name);
            yield return new WaitForSeconds(myanimation[toreloadAnim.name].length);

           

            while (currentammo != clipSize+1 && ammo > 0)
            {
                myAudioSource.time = 0f;

                myanimation.Play(reloadonceAnim.name);
                myAudioSource.clip = reloadonceSound;
                myAudioSource.pitch = Random.Range(0.9f, 1.1f);
                myAudioSource.Play();


                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.7f);

                currentammo += 1;
                ammo -= 1;

                inventory.UpdateCurrentWeaponAmmo(ammo);

                yield return new WaitForSeconds(myanimation[reloadonceAnim.name].length * 0.3f);

                myanimation.Stop();

            }
            myanimation.Play(reloadlastAnim.name);

            yield return new WaitForSeconds(myanimation[reloadlastAnim.name].length);
            isreloading = false;
            canaim = true;
           
            canfire = true;


        }
    }
    
    IEnumerator setfire()
    {
        myanimation.Stop();
        myaudioLastTime = 0f;
        myAudioSource.time = myaudioLastTime;

        if (currentammo > 1) {
            flashthemuzzle();
           
            weaponfirer.fire();
            cameracontroller.dorecoil(recoil);
            fireAudioSource.clip = fireSound;
            fireAudioSource.pitch = Random.Range(0.9f, 1.1f);
            fireAudioSource.Play ();
                       
            
            myanimation.Play (fireAnim.name);
            currentammo -= 1;
            yield return new WaitForSeconds (myanimation[fireAnim.name].length);
            myAudioSource.clip = pumpSound;
            myAudioSource.Play();
            canaim = false;

            myanimation.Play(pumpAnim.name);

            StartCoroutine (ejectshell (myanimation[pumpAnim.name].length* shellejectdelay));
            yield return new WaitForSeconds (myanimation[pumpAnim.name].length);
            canaim = true;

        }
        else if (currentammo <= 1)
        {
            if (currentammo <= 0) {
                reload ();
            }
            cameracontroller.dorecoil(recoil);
            flashthemuzzle();
            weaponfirer.fire();
            fireAudioSource.clip = fireSound;
            fireAudioSource.pitch = 0.9f + 0.1f * Random.value;
            fireAudioSource.Play ();

            myanimation.Play (fireAnim.name);

            currentammo -= 1;
            yield return new WaitForSeconds (myanimation[fireAnim.name].length);
        }
       
       

    }

    void pickAmmo(int inventoryAmmo){
        ammo=inventoryAmmo;
    }
    IEnumerator setMelee(float waittime)
    {
        myAudioSource.clip = meleeSound;
        myAudioSource.Play();
        myanimation.Play(meleeAnim.name);
        yield return new WaitForSeconds (waittime);
        weaponfirer.fireMelee();
    }
    IEnumerator setThrowGrenade()
    {
        canfire = false;
        retract = true;
        grenadethrower.gameObject.SetActive(true);
        grenadethrower.gameObject.BroadcastMessage("throwstuff");
        Animation throwerAnimation = grenadethrower.GetComponent<Animation> ();

        yield return new WaitForSeconds(throwerAnimation.clip.length);
        retract = false;
        canaim = true;
        canfire = true;
        grenadethrower.gameObject.SetActive(false);
    }
    IEnumerator setsyringeshot()
    {
        canfire = false;
        retract = true;
        syringeshooter.gameObject.SetActive(true);
        syringeshooter.gameObject.BroadcastMessage("shootsyringe");
        Animation syringeAnimation = syringeshooter.GetComponent<Animation>();

        yield return new WaitForSeconds(syringeAnimation.clip.length);
        retract = false;
        canaim = true;
        canfire = true;
        syringeshooter.gameObject.SetActive(false);
    }
    void doRetract()
    {
        canaim = false;
        canfire = false;
       
        Camera.main.fieldOfView = normalFOV;



        if (myanimation.IsPlaying(toreloadAnim.name))
        {
            toreload = true;
            lastreloadtime = (myanimation[toreloadAnim.name].normalizedTime);
            Debug.Log("toreload");
        }
        else if (myanimation.IsPlaying(reloadonceAnim.name) )
        {
            reloadonce = true;
            lastreloadtime = (myanimation[reloadonceAnim.name].normalizedTime);
            Debug.Log("reloadonce is true");
        }
       



        else if (myanimation.IsPlaying(reloadlastAnim.name))
        {
            reloadlast = true;
            lastreloadtime = (myanimation[reloadlastAnim.name].normalizedTime);
            Debug.Log("reloadlast");
        }
        else if (myanimation.IsPlaying(pumpAnim.name))

        {
            lastreloadtime = (myanimation[pumpAnim.name].normalizedTime);
           
            ispumping = true;
            Debug.Log("ispumping");
        }
        myaudioLastTime = myAudioSource.time;
        Debug.Log(lastreloadtime);
        if (isreloading)
        {
            retract = true;
        }
        else
        {
            myanimation.Play(hideAnim.name);
        }

    }

}

im sure theres’ no copy running the coroutine, also no duplicate script.

Coroutines run independently, so if you start one multiple times, then you’ll create multiple instances of it.

so where do i start it mutiple times?

Sorry, I didn’t read through your entire code, I just meant that you don’t have to have duplicate scripts to run the coroutine multiple times - in case that helps you locate the problem.

i have no idea why this is happening , giving me headaches. normal reload works fine.
when doing the timed calculated reload it runs twice the amount

nobody?

nevermind
found a duplicate call for the IEnumerator in my inventory script

1 Like