Input Manager

Presented via IInputManager interface, this small but useful system provides you with information about player inputs.

To use this system, inject IInputManager interface into your class, as shown below:

[Inject] private IInputManager inputManager;

Available methods

Vector3 GetMovementDirection()

This method returns normalized movement direction (in screen space). For example, if player is pushing W button on keyboard, this method returns (0, 0, 1).

Example:

Vector3 movementDir = inputManager.GetMovementDirection();

characterController.Move(moveSpeed * Time.deltaTime * cameraController.GetWorldDirection(movementDir));

As you can see in example, you can convert screen space movement direction into world space direction via GetWorldDirection method of CameraController class.


void AddKeyListener(KeyCode key, UnityAction keyDownCallback, UnityAction keyUpCallback)

Registers key listener, its key down and key up callbacks.

Example:

inputManager.AddKeyListener(KeyCode.Space, Jump, null);

void RemoveKeyListener(KeyCode key, UnityAction keyDownCallback, UnityAction keyUpCallback)

Removes key listener

Last updated