Advertisement
Guest User

Switch input where nothing is impossible

a guest
Jan 10th, 2022
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections.Generic;
  4.  
  5. public class DumbInput : MonoBehaviour {
  6.     public KeyCode[] keysToListenFor;
  7.     List<KeyCode> keyCodesThisFrame = new List<KeyCode>();
  8.  
  9.     void Update () {
  10.         keyCodesThisFrame.Clear();
  11.         if( keysToListenFor.Length == 0 ) {
  12.             keysToListenFor = Enum.GetValues(typeof(KeyCode)) as KeyCode[];
  13.         }
  14.        
  15.         foreach( KeyCode key in keysToListenFor ) {
  16.             if( Input.GetKeyDown(key) ) {
  17.                 keyCodesThisFrame.Add(key);
  18.             }
  19.         }
  20.  
  21.         foreach( var key in keyCodesThisFrame ) {
  22.             switch( key ) {
  23.                 case KeyCode.A:
  24.                     Debug.Log("A was hit!");
  25.                     break;
  26.                 case KeyCode.B:
  27.                     Debug.Log("B was hit!!");
  28.                     break;
  29.                 case KeyCode.C:
  30.                     Debug.Log("C was hit!!!");
  31.                     break;
  32.             }
  33.         }
  34.  
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement