Connecting Actions to code
There are multiple ways to work with the Input System’s Actions in your code. In this section, I will give a general overview of the most important topics that should allow you to get started working with the Input System.
To connect your Actions to your code, you will need to import the InputSystem
with the following statement:
using UnityEngine.InputSystem;
There are two ways in which I will discuss connecting Actions to your Code:
- Referencing the Action Asset
- Using the
PlayerInput
component
Note
For more information about alternate ways you can connect Actions to your code, see the following Unity documentation:
https://docs.unity3d.com/Packages/[email protected]/manual/Workflows.html
You can reference the Action Asset creating a variable of type InputActionsAsset
like so:
[SerializeField] private InputActionAsset actions;
You can then assign the value of actions
in the Inspector.
And to reference...