In Joy stick, we don’t know what is key value of buttons sometimes. This is to check which key value.
Design
- Camera
- Light
- Canvas
- Event System
- Key Logic
Camera
- Main Camera
- Position: (0, 1, -10)
Light
- Directional Light
- Position: (0, 3, 0)
- Rotation: (50, -30, 0)
Canvas
- Image
- To paint Canvas
- Text1
- Text: “Input value: “
- Text2
- To show key value
Event System
- Event System
- To detect input
Key Logic
- Empty Object
Key Text.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class KeyTest : MonoBehaviour {
public Text keytext;
void Start () {
keytext.text = "";
}
void Update () {
foreach(KeyCode key in System.Enum.GetValues(typeof(KeyCode))){
if (Input.GetKeyUp(key)){
print(key.ToString());
keytext.text = key.ToString();
}
}
}
}
- Keytext: Text2
UI

