Ejemplo n.º 1
0
 /// <summary>
 /// One click, one shot, but no reload action.
 /// </summary>
 private void fireSemiautomatic(PlayerFiringState state)
 {
     if (!state.alreadyFired)
     {
         fireBullet();
         gunAudioSource.PlayOneShot(fireSound, Settings.volume);
     }
     state.alreadyFired = true;
 }
Ejemplo n.º 2
0
 /// <summary>
 /// Continuous fire while button is held down.
 /// </summary>
 private void fireAutomatic(PlayerFiringState state)
 {
     if (fireDelay < 0.03f)
     {
         if (!gunAudioSource.isPlaying)
         {
             gunAudioSource.volume = Settings.volume;
             gunAudioSource.PlayOneShot(autoStart, Settings.volume);
             gunAudioSource.PlayScheduled(AudioSettings.dspTime + autoStart.length);
         }
     }
     else
     {
         gunAudioSource.PlayOneShot(fireSound, Settings.volume);
     }
     fireBullet();
     state.firingAutomatic = true;
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Fires a bullet based on the firearm action. Also mutates the given
    /// PlayerShoot state.
    /// </summary>
    /// <param name="state">current state of PlayerShoot</param>
    /// <returns>updated state</returns>
    public PlayerFiringState fire(PlayerFiringState state)
    {
        switch (action)
        {
        case FirearmAction.Automatic:
            fireAutomatic(state);
            break;

        case FirearmAction.Semiautomatic:
            fireSemiautomatic(state);
            break;

        case FirearmAction.SingleShot:
            // ... would require manual reload action, not implemented.
            break;

        default:
            break;
        }
        state.nextLossCost         = bulletCost;
        state.needToUpdateLossFeed = true;
        return(state);
    }