public void Shoot()
 {
     if (Time.time > nextShotTime)
     {
         nextShotTime = Time.time + msBetweenShots / 1000;
         Projectiles newProjectile = Instantiate(projectile, muzzle.position, muzzle.rotation) as Projectiles;
         newProjectile.SetSpeed(muzzleVelocity);
     }
 }
    void Shoot()
    {
        if (Time.time > nextShotTime && ammoRemaining > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                if (ammoRemaining == 0)
                {
                    break;
                }
                ammoRemaining--;
                if (ammoRemaining == 0)
                {
                    DamagePopup popupInstance = Instantiate(ammoPopup, transform.position + Vector3.up * 2f, Quaternion.AngleAxis(70, Vector3.right)) as DamagePopup;
                    popupInstance.JustStart(2f, transform.position + Vector3.up * 2f);
                }
                nextShotTime = Time.time + RateOfFire / 1000;
                Projectiles newBullet = Instantiate(bullet, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectiles;
                newBullet.SetSpeed(muzzleVel);
                newBullet.SetDamage(bulletDamage + (int)Random.Range(-damageVariance, damageVariance));
            }
            if (UpdateAmmo != null)
            {
                UpdateAmmo();
            }
            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleFlash.Activate();

            transform.localPosition -= Vector3.forward * .2f;
            recoilAngle             += recoilPerShot;
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, maxRecoilAngle);

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }
Exemple #3
0
    void Shoot()
    {
        if (!isReloading && Time.time > nextShotTime && projectilesRemainingInMag > 0)
        {
            if (fireMode == FireMode.Burst)
            {
                if (shotsRemainingInBurst == 0)
                {
                    return;
                }
                shotsRemainingInBurst--;
            }
            else if (fireMode == FireMode.Single)
            {
                if (!triggerReleasedSinceLastShot)
                {
                    return;
                }
            }

            for (int i = 0; i < projectileSpawn.Length; i++)
            {
                if (projectilesRemainingInMag == 0)
                {
                    break;
                }
                projectilesRemainingInMag--;
                nextShotTime = Time.time + msBetweenShots / 1000;
                Projectiles newProjectile = Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation) as Projectiles;
                newProjectile.SetSpeed(muzzleVelocity);
            }

            Instantiate(shell, shellEjection.position, shellEjection.rotation);
            muzzleflash.Activate();
            transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y);
            recoilAngle             += Random.Range(recoilAngleMinMax.x, recoilAngleMinMax.y);
            recoilAngle              = Mathf.Clamp(recoilAngle, 0, 30);

            AudioManager.instance.PlaySound(shootAudio, transform.position);
        }
    }