Using HotKeys to select actions

So I always prefer to not have to click on things, so I added the tab key to switch between possible units with action points.

The next obvious step was action selection with the number keys.

The solution i came up with was to apply a ‘Scale’ to the action keys depending on what key was entered
eg. 1[keyboard] has a scale of 0, returns 0 when clicked.

This well let us return [0] from an array.

InputManager

    public bool GetActionInput(out int keyIndex)
    {
        if (playerInputActions.Player.ActionSelection.WasPressedThisFrame())
        {
            keyIndex = (int)playerInputActions.Player.ActionSelection.ReadValue<float>();
            return true;
        }
        else
        {
            keyIndex = -1;
            return false;
        }
    }

UnitActionSystem

   void TrySelectNewActionHotkey()
    {
        int actionIndex;
        if(InputManager.Instance.GetActionInput(out actionIndex))
        {
            var selectedUnitAvailableActions = selectedUnit.GetBaseActionArray();
            if(selectedUnitAvailableActions[actionIndex] != null)
            {
                SetSelectedAction(selectedUnitAvailableActions[actionIndex]);
            }
        }
    }

That’s a great addition, good job!
Although when accessing the BaseActionArray you need to check if the index is valid before accessing it, otherwise you will get an IndexOutOfRangeException.

Privacy & Terms