// Update is called once per frame void Update() { // we check inputs and if buttons are pressed, the appropriate events will be fired #region "Forward (W)" if (Input.GetKeyDown(KeyCode.W)) { OnForwardKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.W)) { OnForwardKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.W)) { OnForwardKeyReleased?.Invoke(); } #endregion #region "Backward (S)" if (Input.GetKeyDown(KeyCode.S)) { OnBackwardKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.S)) { OnBackwardKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.S)) { OnBackwardKeyReleased?.Invoke(); } #endregion #region "Left (A)" if (Input.GetKeyDown(KeyCode.A)) { OnLeftKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.A)) { OnLeftKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.A)) { OnLeftKeyReleased?.Invoke(); } #endregion #region "Right (D)" if (Input.GetKeyDown(KeyCode.D)) { OnRightKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.D)) { OnRightKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.D)) { OnRightKeyReleased?.Invoke(); } #endregion #region "Running (Left Shift)" if (Input.GetKeyDown(KeyCode.LeftShift)) { OnRunningKeyPressed?.Invoke(); } if (Input.GetKey(KeyCode.LeftShift)) { OnRunningKeyHold?.Invoke(); } if (Input.GetKeyUp(KeyCode.LeftShift)) { OnRunningKeyReleased?.Invoke(); } #endregion #region "Left Click (Mouse1)" if (Input.GetMouseButtonDown(0)) { OnLeftClickPressed?.Invoke(); } if (Input.GetMouseButton(0)) { OnLeftClickHold?.Invoke(); } if (Input.GetMouseButtonUp(0)) { OnLeftClickReleased?.Invoke(); } #endregion #region "Right Click (Mouse2)" if (Input.GetMouseButtonDown(1)) { OnRightClickPressed?.Invoke(); } if (Input.GetMouseButton(1)) { OnRightClickHold?.Invoke(); } if (Input.GetMouseButtonUp(1)) { OnRightClickReleased?.Invoke(); } #endregion #region "Jump (Spacebar)" if (Input.GetKeyDown(KeyCode.Space)) { OnJumpButtonPressed?.Invoke(); } #endregion #region "Lock On (F)" if (Input.GetKeyDown(KeyCode.F)) { OnLockOnButtonPressed?.Invoke(); } #endregion }
/// <summary> /// Awake /// </summary> private void Awake() { GameInputActions = new GameInputActions(); GameInputActions.UsagesActionMap.Any.performed += (context) => { if (onAnyKeyPressed != null) { onAnyKeyPressed.Invoke(); } OnAnyKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Back.performed += (context) => { if (onBackKeyPressed != null) { onBackKeyPressed.Invoke(); } OnBackKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Cancel.performed += (context) => { if (onCancelKeyPressed != null) { onCancelKeyPressed.Invoke(); } OnCancelKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Forward.performed += (context) => { if (onForwardKeyPressed != null) { onForwardKeyPressed.Invoke(); } OnForwardKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Menu.performed += (context) => { if (onMenuKeyPressed != null) { onMenuKeyPressed.Invoke(); } OnMenuKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Modifier.performed += (context) => { if (onModifierKeyPressed != null) { onModifierKeyPressed.Invoke(); } OnModifierKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.PrimaryAction.performed += (context) => { if (onPrimaryActionKeyPressed != null) { onPrimaryActionKeyPressed.Invoke(); } OnPrimaryActionKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.PrimaryTrigger.performed += (context) => { if (onPrimaryTriggerKeyPressed != null) { onPrimaryTriggerKeyPressed.Invoke(); } OnPrimaryTriggerKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.SecondaryAction.performed += (context) => { if (onSecondaryActionKeyPressed != null) { onSecondaryActionKeyPressed.Invoke(); } OnSecondaryActionKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.SecondaryTrigger.performed += (context) => { if (onSecondaryTriggerKeyPressed != null) { onSecondaryTriggerKeyPressed.Invoke(); } OnSecondaryTriggerKeyPressed?.Invoke(); }; GameInputActions.UsagesActionMap.Submit.performed += (context) => { if (onSubmitKeyPressed != null) { onSubmitKeyPressed.Invoke(); } OnSubmitKeyPressed?.Invoke(); }; }