private void shoot() { if (Time.time > nextShotTime) { if (fireMode == FireMode.Burst) { if (shotsRemainingInBurst == 0) { return; } shotsRemainingInBurst--; } else if (fireMode == FireMode.Single) { if (!triggerReleasedSinceShot) { return; } } for (int i = 0; i < projectileSpawn.Length; i++) { nextShotTime = Time.time + msBetweenShots / 1000; GameObject newProjectile = (GameObject)Instantiate(projectile, projectileSpawn[i].position, projectileSpawn[i].rotation); newProjectile.GetComponent <Projectile>().setSpeed(muzzleVelocity); } Instantiate(shell, shellEjector.position, shellEjector.rotation); muzzleFlash.activate(); } }
void shoot() { if (!reloading && Time.time > nextShotTime && remainingBulletsInMag > 0) { if (firemode == FireMode.burst) { if (shotsRemainingInBurst == 0) { return; } shotsRemainingInBurst--; } else if (firemode == FireMode.single) { if (!triggerRelease) { return; } } for (int i = 0; i < muzzles.Length; i++) { if (remainingBulletsInMag == 0) { break; } remainingBulletsInMag--; nextShotTime = Time.time + msBetweenShot / 1000; Projectile newProjectile = (Projectile)Instantiate(bullet, muzzles[i].position, muzzles[i].rotation); newProjectile.setSpeed(muzzleVelocity); } Instantiate(shell, shellEjection.position, shellEjection.rotation); muzzleFlash.activate(); recoilAngle += Random.Range(recoilMinMax.x, recoilMinMax.y); Mathf.Clamp(recoilAngle, 0, 30); transform.localPosition -= Vector3.forward * Random.Range(kickMinMax.x, kickMinMax.y); AudioManager.instance.playSound(shootAudio, transform.position); } }