For example: I have this line of code:
private string customKey = "A";
And I would like to get Keycode.A
by using customKey
, andKeycode.customKey
won't work. Could someone tell me how to do this?
CodePudding user response:
As mentioned in this, you can use Enum.Parse
:
private string key = "A";
private KeyCode customKeyCode;
private void Start()
{
customKeyCode = (KeyCode) System.Enum.Parse(typeof(KeyCode), key);
}
private void Update()
{
if (Input.GetKeyDown(customKeyCode))
{
print(key);
}
}