Skip to content

Instantly share code, notes, and snippets.

@kleberandrade
Created February 21, 2020 17:02
Show Gist options
  • Save kleberandrade/da57cbaf6d88a5ce5e7ba98a6b477e10 to your computer and use it in GitHub Desktop.
Save kleberandrade/da57cbaf6d88a5ce5e7ba98a6b477e10 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class GamepadTester : MonoBehaviour
{
public int m_NumSticks;
public Text m_Joysticks;
public Text[] m_InputText;
public Text[] m_ButtonText;
private void Start()
{
int i = 0;
string sticks = "Joysticks\n";
foreach (string joyName in Input.GetJoystickNames())
{
sticks += i.ToString() + ":" + joyName + "\n";
i++;
}
m_Joysticks.text = sticks;
m_NumSticks = i;
}
private void Update()
{
for (int i = 1; i <= m_NumSticks; i++)
{
string inputs = "Joystick " + i + "\n";
string stick = "Joy " + i + " Axis ";
for (int a = 1; a <= 10; a++)
{
inputs += "Axis " + a + ":" + Input.GetAxis(stick + a).ToString("0.00") + "\n";
}
m_InputText[i - 1].text = inputs;
}
string buttons = "Buttons 3\n";
for (int b = 0; b <= 10; b++)
{
buttons += "Btn " + b + ":" + Input.GetButton("Joy 3 Button " + b) + "\n";
}
m_ButtonText[2].text = buttons;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment