- Home /
Gamepad control on android problem
Hi, I would like for my game, control the player with gamepad on android but I use
if(Input.GetButton("joystick button 0"){ //Do something }
on my computer it work ( the gamepad is connected by USB ) but when I play on android device nothing happenned ( the gamepad is compatible with my tablet ( I Start the game with the game pad))
Please help me :) Regard. Titanics tutos
Answer by CleverZ · May 26, 2017 at 06:09 PM
Confirm the button name, my joystick button 0 on unity was the joystick button 15 on android.
Here is a simple code you can use, attach this to any game object:
public class JoystickTest : MonoBehaviour {
private string joystickButton;
private void OnGUI()
{
GUIStyle style = new GUIStyle("Label");
style.fontSize = 60;
GUI.Label(new Rect(Screen.width / 2 - 100f, Screen.height / 2, 500f, 500f), joystickButton, style);
}
// Update is called once per frame
void Update () {
for (int i = 0; i < 20; i++)
{
if (Input.GetKeyDown("joystick button " + i))
{
joystickButton = "joystick button " + i;
}
}
}
}
Hi guys thanks you very much it work perfectly ! After much testing I finally succeeded thanks to your help
I invite you to subscribe to my youtube channel to see my little project to which your help was my precious;) The video will be released shortly. https://www.youtube.com/channel/UCP$$anonymous$$q80X0G12wY1c5rkfZyzg