/// <summary> /// fire the machine gun /// </summary> void MachineGun_Fire() { if (bulletsLeft <= 0 && numberOfClips > 0) { StartCoroutine(reload()); return; } // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { switch (typeOfBullet) { case BulletType.Physical: StartCoroutine(FireOneShot()); // fire a physical bullet break; case BulletType.Raycast: StartCoroutine(FireOneRay()); // fire a raycast.... change to FireOneRay break; default: Debug.Log("error in bullet type"); break; } if (Animat != null) { if (isAmed) { Animat.AimFire(); } else { Animat.Fire(); } } if (Sync) { Sync.Firing(weaponType.Machinegun.ToString(), spread); } audio.clip = FireSound; audio.spread = Random.Range(1.0f, 1.5f); audio.pitch = Random.Range(1.0f, 1.05f); audio.Play(); shotsFired++; bulletsLeft--; nextFireTime += fireRate; EjectShell(); Kick(); StartCoroutine(CamShake()); StartCoroutine(MuzzleFlash()); } }
/// fire the sniper gun void Sniper_Fire() { if (bulletsLeft <= 0 && numberOfClips > 0) { StartCoroutine(reload()); return; } // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { switch (typeOfBullet) { case BulletType.Physical: StartCoroutine(FireOneShot()); // fire a physical bullet break; case BulletType.Raycast: StartCoroutine(FireOneRay()); // fire a raycast.... change to FireOneRay break; default: Debug.Log("error in bullet type"); break; } if (Animat != null) { Animat.Fire(); } if (Sync) { Vector3 position = (typeOfGun == weaponType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(weaponType.Sniper.ToString(), spread, position, transform.parent.rotation); } StartCoroutine(DelayFireSound()); shotsFired++; bulletsLeft--; nextFireTime += fireRate; EjectShell(); Kick(); StartCoroutine(CamShake()); if (!isAmed) { StartCoroutine(MuzzleFlash()); } //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload()); } } }
/// <summary> /// burst shooting /// </summary> /// <returns></returns> IEnumerator Burst_Fire() { int shotCounter = 0; // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - Info.FireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { while (shotCounter < roundsPerBurst) { isBursting = true; StartCoroutine(FireOneShot()); // fire a physical bullet shotCounter++; shotsFired++; bulletsLeft--; // subtract a bullet Kick(); EjectShell(); bl_EventHandler.OnLocalPlayerShake(ShakeIntense, 0.25f, 0.03f, isAmed); if (muzzleFlash) { muzzleFlash.Play(); } if (Sync) { Vector3 position = (Info.Type == GunType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(GunType.Burst.ToString(), spread, position, transform.parent.rotation, Info.Damage); } if (Animat != null) { Animat.Fire(); } if (FireSound) { Source.clip = FireSound; Source.spread = Random.Range(1.0f, 1.5f); Source.Play(); } yield return(new WaitForSeconds(lagBetweenShots)); } nextFireTime += Info.FireRate; //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload()); } } isBursting = false; }
/// <summary> /// fire the shotgun /// </summary> void ShotGun_Fire() { int pelletCounter = 0; // counter used for pellets per round if (bulletsLeft <= 0 && numberOfClips > 0) { StartCoroutine(reload()); // if out of ammo, reload return; } // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { do { switch (typeOfBullet) { case BulletType.Physical: StartCoroutine(FireOneShot()); // fire a physical bullet break; case BulletType.Raycast: StartCoroutine(FireOneRay()); // fire a raycast.... change to FireOneRay break; default: Debug.Log("error in bullet type"); break; } if (Sync) { Sync.Firing(bl_Gun.weaponType.Shotgun.ToString(), spread); } pelletCounter++; // add another pellet shotsFired++; // another shot was fired } while (pelletCounter < pelletsPerShot); // if number of pellets fired is less then pellets per round... fire more pellets StartCoroutine(DelayFireSound()); if (Animat != null) { Animat.Fire(); } StartCoroutine(CamShake()); EjectShell(); // eject 1 shell nextFireTime += fireRate; // can fire another shot in "firerate" number of frames bulletsLeft--; // subtract a bullet Kick(); } }
void Knife_Fire() { // If there is more than one shot between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { switch (typeOfBullet) { case BulletType.Physical: StartCoroutine(FireOneShot()); // fire a physical bullet break; case BulletType.Raycast: StartCoroutine(FireOneRay()); // fire a raycast.... change to FireOneRay break; default: Debug.Log("error in bullet type"); break; } if (Animat != null) { if (isAmed) { Animat.AimFire(); } else { Animat.Fire(); } } if (Sync) { Vector3 position = (typeOfGun == weaponType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(weaponType.Knife.ToString(), 0, position, transform.parent.rotation); } GetComponent <AudioSource>().clip = FireSound; GetComponent <AudioSource>().spread = Random.Range(1.0f, 1.5f); GetComponent <AudioSource>().pitch = Random.Range(1.0f, 1.05f); GetComponent <AudioSource>().Play(); nextFireTime += fireRate; Kick(); StartCoroutine(CamShake()); isFiring = false; } }
IEnumerator Launcher_Fire() { // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - Info.FireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } bool already = false; // Keep firing until we used up the fire time while (nextFireTime < Time.time) { if (!already) { nextFireTime += Info.FireRate; // can fire another shot in "fire rate" number of frames if (Animat != null) { Animat.Fire(); } yield return(new WaitForSeconds(DelayFire)); Vector3 angular = (Random.onUnitSphere * 10f); StartCoroutine(FireOneProjectile(angular)); // fire 1 round bulletsLeft--; // subtract a bullet Kick(); if (Sync) { Vector3 position = (Info.Type == GunType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.FiringGrenade(spread, position, transform.parent.rotation, angular); } if (FireSound) { Source.clip = FireSound; Source.spread = Random.Range(1.0f, 1.5f); Source.Play(); } bl_EventHandler.OnLocalPlayerShake(ShakeIntense, 0.75f, 0.07f, isAmed); isFiring = false; //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload(1.2f)); } already = true; } else { yield break; } } }
IEnumerator Launcher_Fire() { // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } bool already = false; // Keep firing until we used up the fire time while (nextFireTime < Time.time) { if (!already) { nextFireTime += fireRate; // can fire another shot in "firerate" number of frames if (Animat != null) { Animat.Fire(); } yield return(new WaitForSeconds(DelayFire)); StartCoroutine(FireOneProjectile()); // fire 1 round bulletsLeft--; // subtract a bullet Kick(); if (Sync) { Vector3 position = (typeOfGun == weaponType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(weaponType.Launcher.ToString(), spread, position, transform.parent.rotation); } if (FireSound) { GetComponent <AudioSource>().clip = FireSound; GetComponent <AudioSource>().spread = Random.Range(1.0f, 1.5f); GetComponent <AudioSource>().Play(); } StartCoroutine(CamShake()); isFiring = false; //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload()); } already = true; } else { yield break; } } }
/// <summary> /// fire the machine gun /// </summary> void MachineGun_Fire() { // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - Info.FireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { StartCoroutine(FireOneShot()); // fire a physical bullet if (Animat != null) { if (isAmed) { Animat.AimFire(); } else { Animat.Fire(); } } if (Sync) { Vector3 position = (Info.Type == GunType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(GunType.Machinegun.ToString(), spread, position, transform.parent.rotation, Info.Damage); } Source.clip = FireSound; Source.spread = Random.Range(1.0f, 1.5f); Source.pitch = Random.Range(1.0f, 1.05f); Source.Play(); shotsFired++; bulletsLeft--; nextFireTime += Info.FireRate; EjectShell(); Kick(); bl_EventHandler.OnLocalPlayerShake(ShakeIntense, 0.25f, 0.03f, isAmed); if (muzzleFlash) { muzzleFlash.Play(); } //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload()); } } }
/// <summary> /// fire the sniper gun /// </summary> void Sniper_Fire() { isAmed = false; // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - Info.FireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { mIsSniperReloading = true; mLastSniperTime = Time.time; StartCoroutine(FireOneShot()); // fire a physical bullet if (Animat != null) { Animat.Fire(); } if (Sync) { Vector3 position = (Info.Type == GunType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(GunType.Sniper.ToString(), spread, position, transform.parent.rotation, Info.Damage); } StartCoroutine(DelayFireSound()); shotsFired++; bulletsLeft--; nextFireTime += Info.FireRate; EjectShell(); Kick(); bl_EventHandler.OnLocalPlayerShake(ShakeIntense, 0.25f, 0.03f, isAmed); if (!isAmed) { if (muzzleFlash) { muzzleFlash.Play(); } } //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload(delayForSecondFireSound + 0.2f)); } } }
/// <summary> /// fire the shotgun /// </summary> void ShotGun_Fire() { int pelletCounter = 0; // counter used for pellets per round // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - Info.FireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { do { StartCoroutine(FireOneShot()); // fire a physical bullet if (Sync) { Vector3 position = (Info.Type == GunType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(GunType.Shotgun.ToString(), spread, position, transform.parent.rotation, Info.Damage); } pelletCounter++; // add another pellet shotsFired++; // another shot was fired } while (pelletCounter < pelletsPerShot); // if number of pellets fired is less then pellets per round... fire more pellets StartCoroutine(DelayFireSound()); if (Animat != null) { Animat.Fire(); } bl_EventHandler.OnLocalPlayerShake(ShakeIntense, 0.25f, 0.03f, isAmed); EjectShell(); // eject 1 shell nextFireTime += Info.FireRate; // can fire another shot in "fire rate" number of frames bulletsLeft--; // subtract a bullet Kick(); //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload(delayForSecondFireSound + 0.3f)); } } }
/// <summary> /// fire your launcher /// </summary> IEnumerator Launcher_Fire() { if (bulletsLeft == 0) { StartCoroutine(reload()); // if out of ammo, reload yield return(null); } // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { nextFireTime += fireRate; // can fire another shot in "firerate" number of frames if (Animat != null) { Animat.Fire(); } yield return(new WaitForSeconds(DelayFire)); StartCoroutine(FireOneProjectile()); // fire 1 round bulletsLeft--; // subtract a bullet Kick(); if (Sync) { Sync.Firing(weaponType.Launcher.ToString(), spread); } if (FireSound) { audio.clip = FireSound; audio.spread = Random.Range(1.0f, 1.5f); audio.Play(); } StartCoroutine(CamShake()); isFiring = false; } }
/// burst shooting IEnumerator Burst_Fire() { int shotCounter = 0; if (bulletsLeft <= 0 && numberOfClips > 0) { StartCoroutine(reload()); yield break;//return; } // If there is more than one bullet between the last and this frame // Reset the nextFireTime if (Time.time - fireRate > nextFireTime) { nextFireTime = Time.time - Time.deltaTime; } // Keep firing until we used up the fire time while (nextFireTime < Time.time) { while (shotCounter < roundsPerBurst) { isBursting = true; //Debug.Log(" shotCounter = " + shotCounter + ", roundsPerBurst = "+roundsPerBurst); switch (typeOfBullet) { case BulletType.Physical: StartCoroutine(FireOneShot()); // fire a physical bullet break; case BulletType.Raycast: StartCoroutine(FireOneRay()); // fire a raycast.... change to FireOneRay break; default: Debug.Log("error in bullet type"); break; } //Debug.Log("FireOneShot Called in Fire function."); shotCounter++; shotsFired++; bulletsLeft--; // subtract a bullet Kick(); EjectShell(); StartCoroutine(CamShake()); StartCoroutine(MuzzleFlash()); if (Sync) { Vector3 position = (typeOfGun == weaponType.Knife) ? Camera.main.transform.position : muzzlePoint.position; Sync.Firing(weaponType.Burst.ToString(), spread, position, transform.parent.rotation); } if (Animat != null) { Animat.Fire(); } if (FireSound) { GetComponent <AudioSource>().clip = FireSound; GetComponent <AudioSource>().spread = Random.Range(1.0f, 1.5f); GetComponent <AudioSource>().Play(); } yield return(new WaitForSeconds(lagBetweenShots)); } nextFireTime += fireRate; //is Auto reload if (bulletsLeft <= 0 && numberOfClips > 0 && AutoReload) { StartCoroutine(reload()); } } isBursting = false; }