Control Your Player On Mobile Using CrossPlatformInputManager- Game Dev Series 110

Objective: create cross platform control system.

The control method between PC and console is quite different. It can easily to be set on PC by using keyboard. On console, you need to set the code to identify other control system such as a game controller.
Fortunenaeelly, Unity provides a system that allows us can easily setup a cross platform controlling system to our game.

Download Standard Assets

First we need to download a Standard Assets from Unity Assets Store. Click “Assets Store” from drop down menu and open the window.

Search Standard Assets, download and import it.

After imported it, we need to use “MobileSingleStickControl” prefab under CrossPlatformInput folder. Drag that prefab into hierarchy.

Adjust the joystick and buttons

You can replace the icon to yours. Then we can adjust the joystick to bottom left, and jump button to bottom right.

This is my layout, duplicate the button if you need 2.

These are all have default setting about their input definition in code. Select and check their data in inspector.

As joystick, you can set the movement range. And as you can see, it use “Horizontal” as axis input name, that is what we are going to use in game.
Next is those buttons.

The default name would be “Jump”, we can change them into names that we could easily identify.

After reset those names, we can use them in our code.

Using CrossPlatformInput

Open Player script. First we need to get access to the library before using CrossPlatformInput.

With this line, we can call CrossPlatformInputManager to use this asset.
Locate the line that checks movement input, and replace the controlling method to CrossPlatformInputManager.GetAxisRaw(“Horizontal”).

Then replace both Jump and Attack function to buttons we just renamed.

All done! We can test our game by using these input system on screen, or you can build this game and install it to your mobile to test.

--

--

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