- Home /
C# Script Simulating Input.inputString
I'm trying to make a script which acts as a larger version of Input.inputString that covers all Keycodes Unity has available. However I concerned about it not simulating Input.inputString syntax wise. Is there anyway I could view the Input class and find the code that uses inputString? If not what other means could I use to simulate it?
using UnityEngine;
using System.Collections;
public class InputString : MonoBehaviour {
private KeyCode[] keyCodes =(KeyCode[])System.Enum.GetValues(typeof(KeyCode));
public string inputString;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update (){
for (int i = 0; i < keyCodes.Length; i++)
if (Input.GetKeyDown(keyCodes[i])) {
inputString = keyCodes[i].ToString();
}
}
}
enums do not derive from anything, they map to integer values typically. But you can get an enum as a string, and convert a string to its enum equivalent if that string is one of the valid values of that enum using System.Enum.Parse
Your answer
Follow this Question
Related Questions
Key not recognized 2 Answers
Issue With Lists and Keycodes 1 Answer
Last key pressed 1 Answer
How to Use Key Combinations with the Control-Key? 2 Answers
Dynamic KeyCode Unity Exception 2 Answers