PlayerCharacter.UpdateGunAction C# (CSharp) Method

UpdateGunAction() protected method

Called by the owning client from the InputPoller.Poll function within a subclass to update the player's current weapon.
protected UpdateGunAction ( ) : void
return void
    protected virtual void UpdateGunAction()
    {
        if (!myNetworkView.isMine)
        {
            Debug.LogError("Attempting to call UpdateGunAction when we're not the owner!");
        }
        else if (!IsDying)
        {
            // Weapon selection
            for (KeyCode kc = KeyCode.Alpha1; (int)kc <= (int)KeyCode.Alpha4; kc++)
            {
                if (Input.GetKey(kc))
                {
                    WeaponDirector.PlayerWeapon weapon = (WeaponDirector.PlayerWeapon)((int)kc - (int)KeyCode.Alpha0 - 1);
                    if (PlayerDirector.ActiveSession.HasWeapon(weapon))
                    {
                        // Make sure the PlayerDirector is keen on the current weapon
                        PlayerDirector.ActiveSession.CurrentWeapon = weapon;
                        // Now assign the weapon to this character. Other clients will be updated through network serialization
                        SetActiveWeapon("Player" + weapon.ToString());
                    }
                }
            }

            // Firing actions by mouse clicks or gamepad button presses
            if (Input.GetButtonDown("Fire1"))
            {
                // TODO: If the player fires with the gamepad, the bullets will always go on the X+ axis; but it looks
                // silly if their arm is not also on the X+ axis.
                bool fireLocalAxis = Input.GetMouseButtonDown(0);
                activeWeapon.BeginFiringPrimary(fireLocalAxis ? WeaponFiringDirection.LocalAxis : WeaponFiringDirection.XAxis, characterColor);
            }
            else if (Input.GetButtonUp("Fire1"))
            {
                activeWeapon.EndFiringPrimary();
            }
        }
    }