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.

--

--

--

A passionate gamer whose goal is to work in video game development.

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

Recommended from Medium

Ammo Collected!- Game Dev Series 36

Publish Your Game to Google Play- Game Dev Series 117

State Descriptions on Android

Image showing media controls and the text “Play/pause button — paused, double tap to play”. “Play/pause button — paused” is highlighted as content description and “play” in “double tap to play” is highlighted as the click label

Setup Android App Pen-testing environment on Mac-book M1

Project 7: ESP32 Bluetooth

Android — Shortcut Manager

How to run an expensive calculation with Kotlin Coroutines on the Android Main Thread without…

Clean Your Android Studio to Fix Issues

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
S.J. Jason Liu

S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

More from Medium

Day 105: Working with Animation Events in Unity

Camera plugin for Unity

Using GameDevHQ’s FileBase Asset Database For HQ Models

Adding a player ammo indicator to the UI