コード例 #1
0
    void FireGun()
    {
        if (gunHandler.status == GunHandler.GunStatus.reloading || gunHandler.CantContinueShooting())
        {
            return;
        }

        shootingGun = true;
        GunObject gun = gunHandler.gun;

        fireTimer = gun.firerate;

        switch (gun.shooting)
        {
        case GunObject.ShootType.semi:
            PlayShotSFX();
            float addTime = gun.firerate / (float)semiCalculations;
            StartCoroutine(singleShot());
            if (!gunHandler.ShootGun())
            {
                AutoReloadGun(gunHandler.gunIndex);
            }
            IEnumerator singleShot()
            {
                SimulateShot();
                for (int i = 0; i < semiCalculations; i++)
                {
                    continuousShots++;
                    ApplyRecoil(addTime);
                    yield return(new WaitForSeconds(addTime));
                }
                shootingGun = false;
            }

            fireDelayTimer = 0;     //Restart the timer if semi or burst
            break;

        case GunObject.ShootType.auto:
            PlayShotSFX();
            SimulateShot();
            ApplyRecoil(gun.firerate);
            if (!gunHandler.ShootGun())
            {
                AutoReloadGun(gunHandler.gunIndex);
            }
            shootingGun = false;
            break;

        case GunObject.ShootType.burst:
            PlayShotSFX();
            float shotTime = gun.burstTime / (float)gun.burstShot;
            StartCoroutine(burstShot());
            IEnumerator burstShot()
            {
                for (int i = 0; i < gun.burstShot; i++)
                {
                    SimulateShot();
                    continuousShots++;
                    ApplyRecoil(shotTime);
                    if (!gunHandler.ShootGun())
                    {       //Stop when we run out of bullets
                        AutoReloadGun(gunHandler.gunIndex);
                        yield return(null);
                    }
                    else
                    {
                        yield return(new WaitForSeconds(shotTime));
                    }
                }
                shootingGun = false;
            }

            fireDelayTimer = 0;     //Restart the timer if semi or burst
            break;
        }
    }