Cross-platform Input Controller

Simon Leen
3 min readOct 6, 2021

--

Objective: Set up cross platform controls

Unity provides its own set of cross-platform input controls. To use them, you just need to add the asset to your assets in the Asset Store and them import them using the package manager within Unity.

This will be done using Unity 2020.3, older versions may differ in setup.

Once imported, I faced an error that one part was obsolete and needed to be fixed. As you can see in the images below, GUIText is no longer supported and caused a slight error.

This was an easy fix as seen below by using the UnityEngine.UI and changing GUIText to Text fixed the issues.

Next we add the MobileSingleStickControl from the assets to the hierarchy.

Initially they give a default joystick and a button shown below.

We have our own button styles and joystick so after swapping out the source images and editing the size, scale, positions and adding a second button, we have the following layout.

Next we will add the funtionality for the joystick by adding the namespace using UnityStandardAssets.CrossPlatformInput and swapping out Input for CrossPlatformInputManager. This will detect the build and use the appropriate input settings.

For the buttons, we can take the A button for example, select it and in the inspector, there’s a button handler that we can name to use in the code. It’s name has been set to A_Button.

We can now use the CrossPlatformInputManager to use the A_Button where the Space Key was already being used.

We do the same process for the B_Button for Attack and we now have working mobile controls.

--

--

No responses yet