Exemplo n.º 1
0
    private void Awake()
    {
        controls = new FPSPlayerControls();

        // Fire controls
        playerActions = controls.Player;
        playerActions.Fire.performed += ctx => { isFiring = true; };
        playerActions.Fire.canceled  += ctx => { isFiring = false; };

        // Movement controls
        playerActions.Move.performed += ctx =>
        {
            isMoving = true;
        };
        playerActions.Move.canceled += ctx =>
        {
            isMoving = false;
        };
        playerActions.Jump.performed += ctx =>
        {
            isJumping = true;
        };
        playerActions.Jump.canceled += ctx =>
        {
            isJumping = false;
        };
        playerActions.Dash.performed += ctx =>
        {
            if (canDash)
            {
                StartCoroutine(Dash());
            }
        };
        playerActions.Interact.performed += ctx =>
        {
            if (interactionTarget)
            {
                interactionTarget.started += () =>
                {
                    Cursor.lockState = CursorLockMode.None;
                    Cursor.visible   = true;
                    playerActions.Disable();
                };
                interactionTarget.finished += () =>
                {
                    Cursor.lockState = CursorLockMode.Locked;
                    Cursor.visible   = false;
                    playerActions.Enable();
                };
                interactionTarget.HandleInteraction(gameObject);
            }
        };

        // Swap Weapon Controls
        playerActions.ScrollWeapon.performed += ctx => {
            if (!isSwitchingWeapon)
            {
                var input = ctx.ReadValue <Vector2>();
                var scrollDirectionRaw = Mathf.RoundToInt(input.y == 0 ? input.x : input.y);
                StartCoroutine(SwitchingWeaponDelay(weaponSwitchDuration));
                OnWeaponScroll?.Invoke(Mathf.RoundToInt(scrollDirectionRaw));
                activeWeapon = weaponSwitcher.GetActiveWeapon()?.GetComponent <FPSWeapon>();
            }
        };
    }