Converting Interactable Legacy Input to the New Unity Input System

Let’s take a look at how we can go about changing the interaction controls from the legacy input to the new input system. Let’s first start with how we can adjust our code for interactions that are based off a single click of a key:

As we can see from the legacy code, we have a switch statement set up that determines which type of interaction is occurring. We can reuse this switch statement part of the code and just have it called upon when out interact action has started:

What we have done is repurposed the core aspects of the code, but got rid of the need to implement the KeyState status to determine what we want our key action to do. With this in place, let’s see how it works within our game:

From here, what we can do is look at how we will want to get an interaction in which we have to hold down our key for:

In our original code, we have it set up with a keystate that needs to be held, and it calls upon the HoldAction code that has been used. What we can do is just simply add this to the end of our current switch statement, and not worry about having all of this additional code get place:

Now, let’s see how this looks within the game:

Now that we have it charging when held down, there is a small issue in that we keep charging even when letting go of our key. In order to fix this, we can put in the second part of the legacy code for the end functionality into a cancelled function:

With this, it should now stop our charging period and have the player need to restart from the beginning:

Now, let’s take a look at the difference between how the script is set up from legacy to new input:

As we can see, it doesn’t involve having to make sure we are calling the key press in the script, along with state. This makes it much easier to do the same actions as before.
Now that we have this all set up, we are almost done experimenting changing from a legacy input system to the new input system.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Dear The Chronicle of Philanthropy,

Using PostgreSQL to Create an Efficient Search Engine

How to make anki cards fast (new).

Secret Management in .Net Core Application using Azure Key Vault and Azure DevOps Service — PART 3

WebRTC in a Nutshell (Episode-I)

VIVID Playground 1.5 Release!

Tic Tac Toe

Specflow — Part 2 — Lets dig a lil deeper

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jordan Evans

Jordan Evans

More from Medium

OnCollisionEnter Vs. OnTriggerEnter — When to use them?

GamePad Support w/ New Unity Input System

Unity Basics by making a project

Making Elevators In A Unity Platformer