Receive any Keyboard input and use with Switch statement on Unity

后端 未结 3 1369
萌比男神i
萌比男神i 2021-01-23 04:58

I don\'t want to use if statement. For simplicity and performance I want to use switch case and execute that method. I want all the keyboard Input to get detected. But is there

3条回答
  •  情书的邮戳
    2021-01-23 05:43

    foreach(KeyCode kcode in Enum.GetValues(typeof(KeyCode)))
    {
        if (Input.GetKey(kcode))
        Debug.Log("KeyCode down: " + kcode);
    }
    

    Also you can cache the value of Enum.GetValues(typeof(KeyCode)) for optimization.

提交回复
热议问题