コード例 #1
0
    // Switching between character aiming control schemes based on player rotation input.
    // Isolates rotation code so it doesn't read from multiple sources.
    void FaceDirection(bool disable)
    {
        // If 'disable' boolean is true, then do not apply any rotation forces.
        // Reason: when player is hit by an explosive force, they should roll and flop around
        // for a period of time.
        if (disable)
        {
            return;
        }

        // Read rotation only from Gamepad.
        if (current_state == Control_State.gamepad)
        {
            FaceGamepad();
            // If any input rotation input read from Mouse + Keyboard,
            // then switch to that state.
            if (temp_mouseRotate != mouseRotate)
            {
                current_state    = Control_State.mouseKeyboard;
                temp_mouseRotate = mouseRotate;
            }
        }

        // Read rotation only from Mouse + Keyboard.
        if (current_state == Control_State.mouseKeyboard)
        {
            FaceMouse();
            // If any input rotation input read from the Gamepad,
            // then switch to that state.
            if (temp_gamepadRotate != gamepadRotate)
            {
                current_state      = Control_State.gamepad;
                temp_gamepadRotate = gamepadRotate;
            }
        }
    }
コード例 #2
0
    public override void Awake()
    {
        base.Awake();

        hxpTotal = 0;

        #region Body Card Attributes
        bubbleBrain = transform.Find("Brain").gameObject;
        WearBodyCard();
        #endregion

        #region Rotation Variables
        angle              = 0.0f;
        angleVector        = new Vector2(0, 0);
        center             = new Vector2(0, 1);
        temp_mouseRotate   = mouseRotate;
        temp_gamepadRotate = gamepadRotate;

        beforeRotation  = new Quaternion(0, 0, 0, 0);
        currentRotation = new Quaternion(0, 0, 0, 0);

        #endregion

        #region Movement Variables
        rb = GetComponent <Rigidbody>();
        #endregion

        #region Input Controls

        // Initialize the controls for the player.
        controls_PlayerInput = new PlayerInputActions();

        // Declare the control scheme enum
        current_state = Control_State.gamepad;

        // Y axis Up and Down movement
        controls_PlayerInput.PlayerController.MoveYUp.performed   += ctx => moveVer = ctx.ReadValue <float>();
        controls_PlayerInput.PlayerController.MoveYUp.canceled    += ctx => moveVer = 0f;
        controls_PlayerInput.PlayerController.MoveYDown.performed += ctx => moveVer = -1 * ctx.ReadValue <float>();
        controls_PlayerInput.PlayerController.MoveYDown.canceled  += ctx => moveVer = 0f;

        // X and Z axis movement
        controls_PlayerInput.PlayerController.MoveXZ.performed += ctx => moveHor = ctx.ReadValue <Vector2>();
        controls_PlayerInput.PlayerController.MoveXZ.canceled  += ctx => moveHor = Vector2.zero;

        // Gamepad Aiming
        controls_PlayerInput.PlayerController.StickAim.performed += ctx => gamepadRotate = ctx.ReadValue <Vector2>();
        controls_PlayerInput.PlayerController.StickAim.canceled  += ctx => gamepadRotate = Vector2.zero;

        // Mouse Aiming
        controls_PlayerInput.PlayerController.MouseAim.performed += ctx => mouseRotate = ctx.ReadValue <Vector2>();
        controls_PlayerInput.PlayerController.MouseAim.canceled  += ctx => mouseRotate = Vector2.zero;

        // Fire Bubbles
        controls_PlayerInput.PlayerController.Fire.performed += ctx => fireWeapon = ctx.ReadValue <float>();
        controls_PlayerInput.PlayerController.Fire.canceled  += ctx => fireWeapon = 0f;

        // Dash Movement
        controls_PlayerInput.PlayerController.Dash.performed += ctx => dash = ctx.ReadValue <float>();
        controls_PlayerInput.PlayerController.Dash.canceled  += ctx => dash = 0f;

        #endregion
    }