How to set up simple mobile controls in Unity
Let’s go over how to add mobile controls in Unity.
I will amend the Player script first shown in this article.
First, open Package Manager and install Input System:
Click Yes on the warning pop up. This will disable the old Input system and enable the new:
If you clicked on No, then you can change it under Project Settings-Player:
Add three UI elements, one image and two buttons. On the image add OnScreenStick component and set it to left stick (AndroidGamepad). On the first button add the component OnScreenButton and set it to Button East (AndroidGamepad). On the other button add the same component and set it to Button South(AndroidGamepad):
Open up the Player script. Update the movement function to take in both input from the joystick and keyboard. Do the same for jump and the Attack function: