Skip to content

Instantly share code, notes, and snippets.

@SimonDarksideJ
Created June 5, 2019 10:18
Show Gist options
  • Save SimonDarksideJ/cacfaa15d8a6fa2319e728dff3d2fcb3 to your computer and use it in GitHub Desktop.
Save SimonDarksideJ/cacfaa15d8a6fa2319e728dff3d2fcb3 to your computer and use it in GitHub Desktop.
Simple script used to identify the Unity inputs from a controller (where documentation lets you down)
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GetButtonsDown : MonoBehaviour
{
string[] joysticks;
int joysticksCount = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
joysticks = Input.GetJoystickNames();
if (joysticks.Length != joysticksCount)
{
joysticksCount = joysticks.Length;
Debug.LogError($"Joysticks updated, Count {joysticksCount}");
}
foreach (KeyCode key in Enum.GetValues(typeof(KeyCode)))
{
if (Input.GetKeyDown(key))
{
Debug.LogError($"Key {key.ToString()} Pressed");
}
}
for (int i = 0; i < 20; i++)
{
var axis = Input.GetAxis($"AXIS_{i.ToString()}");
if (axis != 0)
{
Debug.LogWarning($"Axis {i} Pressed");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment