Setup New Unity Input System
Let’s take a look at the new Input system offered by unity and how we can go about using it in our projects. To start, we will want to add it to the projects we wish to use it with:
Once we have installed it, a warning message will pop up. If we follow what is being said by the Unity documentation, which can be found here, we just have to click on yes:
Within the documentation, it says we can enable both if we wanted to. TO do so, we just have to go into our project settings and select both under the active input handling:
While within these settings, we will also want to make sure that our scripting backend is set to IL2CPP along with having our Api Compatibility Level at .NET 4.x.
Now that we have this set up within Unity, let’s take a look at Input actions:
What we will want to do is create a new folder for Input and create a new input action under it. From here, we can open it up and look at what we can do from here:
As you can see, within this new window, we can create our action maps that we desire for the game we are making. What this allows us to do is create different actions based on the situation the player is in. All that we need to do at this point, after coding in the different ways those action maps work, is tell Unity when we switch to a new map.
Let’s look at how we can go about creating a WASD walking system. First off ,we will want to change the properties in the action:
Upon changing our properties to a value type with a control type of vector 2, we can then add a new binding to it:
After changing the values, we can select the 2d vector composite and change the buttons to what we desire them to be.
Now, for creating an interaction that we need to hold a specific button, we have to just go to the interactions of that input and select hold:
From here, we just have to make the changes to the time it takes if we don’t want the default times provided to us.
As for creating an action that needs 2 keys to enact, we will want to select the add button with 1 modifier option and makes our selection of buttons from there:
Now that we have gone through some of the basics of this new input system’s actions through the unity editor, we will look into how we can go about scripting these actions.