Cross-Platform Input in Unity
Now that most of the gameplay mechanics are in my game, it is time to add the ability to control the game on mobile devices.
To start, go to the Unity asset store and get the standard asset pack.
Once you have this go to unity and download the standard assets from the packet manager.
This will add a new folder called standard assets to the project window.
In this folder go to CrossPlatformInput => Prefabs => MobileSingleStickControl.
Drag this into the hierarchy and align the mobile joystick with the one that is already there. You will disable the old one and add the image to the new joystick control to get the right image. Do this with the buttons as well. You will duplicate the button and then align both buttons with the old ones.
On the buttons, go to the button handler and rename them A_Button and B_Button.
To get these working go to the player script. Add the namespace using UnityStandardAssets.CrossPlatformInput. Go to the movement script and replace the Input.GetAxisRaw(“Horizontal”) code with CrossPlatformInputManager.GetAxisRaw(“Horizontal”). You can go through a similar process with jump and attack. These two will use GetButtonDown and the A_Button and B_Button text added in the inspector.
This will allow you to use the buttons.