I’m having a problem with an FPS game that I’m currently developing. When firing the gun, the sound of it is not very good and sort of “raw”. When firing single shots it sounds just fine but when firing on full auto it gets distorted and doesn’t sound like a gun supposed to. Also, it seems like while firing on full auto it skips some shot sounds.
Here’s A sample that I’ve recorded of what I mean: picosong - upload a mp3 or song, get a link to it!
This is the script I use:
var ReloadSound : AudioSource; //reload audio source
var DrySound : AudioSource; //empty magazine audio source
var FireModeSound : AudioSource; //fire mode switching audio source
var Shell : GameObject; // bullet shelll 3d object
var ShellSpawn : Transform; // where the bullet shelll is going to be instantiated from
public var ShootAnim : Animation; // the shooting animation
public var ReloadAnim : Animation; // the reload animation (magazine is not empty)
var ReloadEmptyAnim :Animation; // the reload animation (magazine is empty)
public var IdleAnim : Animation; // the idle animation
public var canShoot : boolean = true; // can the player shoot?
public var canReload : boolean = false; // can the player reload?
public var canAim : boolean = true; // can the player aim down sights?
var clip = 30; // number of bullets in the magazine
var ammoLeft = 320; // maximum ammo you can carry
var TimeBetweenShots : float = 0.09; // controlls the fire rate
var timestamp : float;
var Effect : Transform; // the effect that will be displayed at the bullet's hit position (like: bullet holes, blood, etc..)
var TheDammage = 46; // the damage of a single bullet hit
var AimSound : AudioSource; //aim audio source
var maxBulletSpreadAngle : float = 1.5f; // the bullet spread angle
public var IsAiming : boolean = false; // is the player aiming?
var MagazineDisplay : UnityEngine.UI.Text; // mag HUD
var AmmoLeftDisplay : UnityEngine.UI.Text; // Ammo left HUD
//Muzzle Flash Variables
var MuzzleFlash : Renderer; // muzzle flash texture
var MuzzleLight : Light; // point light
var SmokePuff : GameObject; // smoke particle
var SmokeSpawn : Transform; // position of the smoke particle
public var FireSound : AudioClip; // audio file of a single shot
var SoundSpawn: AudioSource; // audio source for the FireSound file
var FullAuto : boolean = true; // boolean checking for full auto or semi auto
var IsReloading : boolean = false; // is the player reloading?
var finishReload : boolean = false; // player finished reloading?
function Start () {
MuzzleFlash.enabled = false; // disable the muzzle flash texture on start
MuzzleLight.enabled = false; // disable the point light on start
SoundSpawn = GetComponent.<AudioSource>();
}
function Update () {
var hit : RaycastHit;
var ray : Ray = Camera.main.ScreenPointToRay(Vector3(Screen.width*2, Screen.height*2, 0));
var fireDirection : Vector3 = transform.forward;
var fireRotation : Quaternion = Quaternion.LookRotation(fireDirection);
var randomRotation : Quaternion = Random.rotation;
fireRotation = Quaternion.RotateTowards(fireRotation,randomRotation,Random.Range(0.0f,maxBulletSpreadAngle));
if(Input.GetButton("Fire1") && clip > 0 && Time.time >= timestamp && canShoot == true && FullAuto == true){
SoundSpawn.PlayOneShot(FireSound, 0.7F);
clip -= 1;
Fire();
if (Physics.Raycast (transform.position,fireRotation*Vector3.forward, hit, 100))
{
Debug.DrawLine (transform.position, hit.point, Color.green);
var particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
if(Input.GetButtonDown("Reload") && clip != 0 && ammoLeft != 0 && canReload == true && IsReloading == false ){
canAim = false;
canShoot = false;
Reload();
}
if(clip == 0 && ammoLeft > 0 && IsReloading == false){
ReloadSound.Play();
ReloadEmptyAnim.Play("reload_empty");
canAim = false;
canShoot = false;
AutoReload();
}
if(clip != 30 && ammoLeft != 0){
canReload = true;
}
if(Input.GetButton("Fire1") && clip == 0 && ammoLeft == 0 && !ReloadAnim.IsPlaying("reload")){
DryGun();
}
if(Input.GetButtonDown("FireMode") && FullAuto == true){
FullAuto = false;
FireModeSound.Play();
}else if(Input.GetButtonDown("FireMode") && FullAuto == false){
FullAuto = true;
FireModeSound.Play();
}
if(Input.GetButtonDown("Fire1") && clip > 0 && Time.time >= timestamp && canShoot == true && FullAuto == false){
SoundSpawn.PlayOneShot(FireSound, 0.7F);
clip -= 1;
Fire();
if (Physics.Raycast (transform.position,fireRotation*Vector3.forward, hit, 100))
{
Debug.DrawLine (transform.position, hit.point, Color.green);
particleClone = Instantiate(Effect, hit.point, Quaternion.LookRotation(hit.normal));
Destroy(particleClone.gameObject, 2);
hit.transform.SendMessage("ApplyDammage", TheDammage, SendMessageOptions.DontRequireReceiver);
}
}
MagazineDisplay.text = "" + clip;{
AmmoLeftDisplay.text = " /" + ammoLeft;
}
}
function Fire() {
ShootAnim.Play("shoot");
timestamp = Time.time + TimeBetweenShots;
if(ShootAnim.IsPlaying("shoot"))
ShootAnim.Rewind("shoot");
}
function Reload() {
IsReloading = true;
canAim = false;
canReload = true;
ReloadAnim.Play("reload_full");
ReloadSound.Play();
yield WaitForSeconds(3.7);
var totalAmmo = clip + ammoLeft;
if(totalAmmo <= 30){
clip = totalAmmo;
ammoLeft = 0;
}else{
var shotsFired = 30 - clip;
clip = 30;
ammoLeft -= shotsFired;
}
canShoot = true;
canReload = false;
canAim = true;
IsReloading = false;
finishReload = true;
yield WaitForSeconds(0.1);
finishReload = false;
}
function AutoReload() {
IsReloading = true;
yield WaitForSeconds(3.7);
totalAmmo = clip + ammoLeft;
if(totalAmmo <= 30){
clip = totalAmmo;
ammoLeft = 0;
}else{
shotsFired = 30 - clip;
clip = 30;
ammoLeft -= shotsFired;
}
canShoot = true;
canAim = true;
canReload = false;
IsReloading = false;
finishReload = true;
yield WaitForSeconds(0.1);
finishReload = false;
}
function DryGun(){
DrySound.Play();
}
Any Suggestions?