Skip to content

Instantly share code, notes, and snippets.

@davepape
Last active October 24, 2019 20:56
Show Gist options
  • Save davepape/44fe76c5419d0dfdd552d4fa7fcb9acf to your computer and use it in GitHub Desktop.
Save davepape/44fe76c5419d0dfdd552d4fa7fcb9acf to your computer and use it in GitHub Desktop.
Display the state of a few example Unity Input values
// Display the state of a few example Unity Input values
// This script should be attached to a text object.
// It uses the "Jump" and "Cancel" buttons to switch between very slow framerate & 60 fps, so that the behavior of GetButtonDown & GetButtonUp can be seen.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class showInput : MonoBehaviour
{
void Start()
{
QualitySettings.vSyncCount = 0;
}
void Update()
{
string msg = "";
msg += "Fire1: " + Input.GetButton("Fire1") + "\n";
msg += "Fire1 down: " + Input.GetButtonDown("Fire1") + "\n";
msg += "Fire1 up: " + Input.GetButtonUp("Fire1") + "\n";
msg += "Vertical: " + Input.GetAxis("Vertical") + "\n";
msg += "Horizontal: " + Input.GetAxis("Horizontal") + "\n";
msg += "Mouse X: " + Input.GetAxis("Mouse X") + "\n";
msg += "Mouse Y: " + Input.GetAxis("Mouse Y") + "\n";
msg += "Mouse pos: " + Input.mousePosition + "\n";
GetComponent<Text>().text = msg;
if (Input.GetButtonDown("Jump")) Application.targetFrameRate = 1;
if (Input.GetButtonDown("Cancel")) Application.targetFrameRate = 60;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment