Cross Platform Input in Unity

Objective: Set up the cross platform input system in Unity

While my project runs well enough using keyboards controls in the Unity editor, I need to add in some different input to be able to play the game on mobile.

This can be easily achieved in Unity by using the Cross platform input assets provided by Unity.

Most new versions of Unity no longer come with the standard assets as a package but you can still grab it. In your package manager or the asset store search for Standard assets. You will then be able to download and import the package. I only imported the Cross Platform input part of the package.

Once imported you will find some joystick prefabs.

I dragged in the MobileSingleStickControl prefab, this comes with a joystick image and two buttons. I replaced the images with my own.

The first thing to do with the buttons is to change the name that buttons will respond to. There are already some pre-made button handler scripts that will be called when the button is clicked.

I renamed the string to reference the buttons to A_btn and B_btn. These are attack and jump respectively.

For the joystick, the only updated needed for my project is how I’m moving with the keyboards controls.

For each place button I needed to replace the regular button to the new button that are on screen.

Instead of referencing the button needed, like SPACE or LEFT_CLICK to attack or jump I am using the strings I changed earlier on.

Now I can move my character on mobile using the joystick and the button to attack and jump.

Integration support and part-time game developer