Example #1
0
    void Update()
    {
        base.UpdatePlayerInput();

        if (playerInput.Trigger_Right == XInputDotNetPure.ButtonState.Pressed)
        {
            this_WeaponManager.FireGun();
        }

        if (Input.GetKeyDown(KeyCode.P))
        {
            PickWeaponUp(WeaponList.StaticGun);
        }

        #region Set Weapon HUD State

        #region HUD Background
        // Reset WeaponHUDState, just to be safe
        this_WeaponManager.WeaponHUDState = false;

        // If left or right bumper is tapped (not held), quickswitch weapons
        if (playerInput.Bumper_Left == XInputDotNetPure.ButtonState.Pressed || playerInput.Bumper_Right == XInputDotNetPure.ButtonState.Pressed)
        {
            BumperHeldTimer += Time.deltaTime;

            if (BumperHeldTimer > BumperHeldTimerThreshhold)
            {
                // Show Weapon Menu
                this_WeaponManager.WeaponHUDState = true;
            }
        }
        else if (BumperHeldTimer > 0f)
        {
            // if button is released before the threshhold, perform a quickswitch
            if (BumperHeldTimer < BumperHeldTimerThreshhold)
            {
                // Weapon Quickswitch
                if (this_WeaponManager.PreviousWeapon != WeaponList.None)
                {
                    this_WeaponManager.QuickswitchWeapons();
                }
            }

            // Reset timer
            BumperHeldTimer = 0f;
        }
        #endregion

        #region Highlight selected weapon via input
        // If Bumper is held down, state that.
        if (playerInput.Bumper_Left == XInputDotNetPure.ButtonState.Pressed || playerInput.Bumper_Right == XInputDotNetPure.ButtonState.Pressed)
        {
            if (!BumperHeld)
            {
                // Set state
                BumperHeld = true;

                // Reset Weapon Chosen
                WeaponChoice = -1;
            }
        }
        // Otherwise, state that the Bumper is not held down, and show no weapon is selected
        else
        {
            // Only run commands if the Bumper used to be held
            if (!BumperHeld)
            {
                // Switch to weapon last selected
                SwitchToSelectedWeapon();
            }

            // Release bumper state
            BumperHeld = false;

            // Reset Weapon icon choice
            this_WeaponManager.WeaponHUDChoice(-1);
        }

        if (BumperHeld)
        {
            float AnalogStickThreshhold = 0.25f;

            // Left side of right analog stick
            if (playerInput.LookHoriz < -AnalogStickThreshhold)
            {
                if (playerInput.LookVert > AnalogStickThreshhold)
                {
                    WeaponChoice = 7;
                }
                else if (playerInput.LookVert < -AnalogStickThreshhold)
                {
                    WeaponChoice = 5;
                }
                else
                {
                    WeaponChoice = 6;
                }
            }
            // Right side of Right analog stick
            else if (playerInput.LookHoriz > AnalogStickThreshhold)
            {
                if (playerInput.LookVert > AnalogStickThreshhold)
                {
                    WeaponChoice = 1;
                }
                else if (playerInput.LookVert < -AnalogStickThreshhold)
                {
                    WeaponChoice = 3;
                }
                else
                {
                    WeaponChoice = 2;
                }
            }
            else
            {
                if (playerInput.LookVert > AnalogStickThreshhold)
                {
                    WeaponChoice = 0;
                }
                else if (playerInput.LookVert < -AnalogStickThreshhold)
                {
                    WeaponChoice = 4;
                }
                else // Unique state. Does not record weapon choice.
                {
                    this_WeaponManager.WeaponHUDChoice(9);
                }
            }

            // Sets weapon icon
            this_WeaponManager.WeaponHUDChoice(WeaponChoice);
        }
        #endregion

        #endregion

        if (f_DeathTimer > 0f)
        {
            f_DeathTimer -= Time.deltaTime;
            if (f_DeathTimer < 0f)
            {
                f_DeathTimer = 0;
                SpawnPlayer();
            }
        }

        if (Input.GetKeyDown(KeyCode.Escape) || playerInput.Button_Start == XInputDotNetPure.ButtonState.Pressed)
        {
            Application.Quit();
        }
    }