• Home
  • About
    • Hanna's Blog photo

      Hanna's Blog

      I wanna be a global developer.

    • Learn More
    • Email
    • LinkedIn
    • Github
  • Posts
    • All Posts
    • All Tags
  • Projects

[Unity 2017] Check Key Value

17 Nov 2018

Reading time ~1 minute

See this unity games in github.

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

Check Key Value

Demo Video

Download



UnityC#ARVRGame Share Tweet +1