GamePad Support w/ New Unity Input System

With games nowadays, we need to consider applying gameplay functionality for multiple different devices. Some people may enjoy it more with a mouse and keyboard feel, while others prefer using a controller. The task itself for implementing a controller option is really simple when it comes to the new input system. All that is really required is to just apply the buttons you want to have the controller set to as another option for the movement in the game under the action maps:

As we can see, we can simply just place the controls we want to use for a gamepad within the actual actions we have already created. We can go further and set them up so that they are within their own control scheme as well, to make it easier to see if we have all of the controls placed for each of the actions we wish to use:

Once we get all of the gamepad controls sets up to how we would like it, we now need to look into how we can go about changing the UI in the game to let the user know which button to press to interact with the objects. The method I ended up taking is a simple button option upon launch of the game. The button that gets picked will determine which of the controllers the player wishes to play with, and will change the UI to display the button needed to interact with the object:

Once the player chooses his controls, we need to make sure that both of these options disappear from the screen, along with telling the method we will be making what value we want it to be:

As for the method we are calling, it is a simple value check method that will set our int to either a 0 or a 1:

Finally, we can simply go into our UI portion of the script and add in the following:

With this code, we are letting Unity know that, in this case, if the value is 0, the controls we want displayed are for the keyboard. If the value is a 1, we want the controls to be displayed for a PS4 controller. With this all set up, let’s take a look at how it is within the game:

And for the PS4 controller:

There we have it, we have added in the functionality for a controller, along with adding in a little button to let the user know which button will be required to interact with our objects.

--

--

--

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

Recommended from Medium

Again WinForms and NativeAOT

Enemies and Physics

WordPress vs. Drupal — Finding the Best Fit to Power Your Online Presence — Helios Blog

A/B testing (My CXL experience)

Fluwix: The Percent Indicator

How To Integrate MSI Inventory Management In Magento 2?

Thank you community! CTSI is Now Listed on Bancor.

Auth0 — Easy but secure Auth

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

Drone Controls w/ New Unity Input System

OnCollisionEnter Vs. OnTriggerEnter — When to use them?

Learning Unity — How To Make A Loading Screen

Quick tip — How to set up Occlusion Culling in Unity