I dont want to put detection for each key so can i detect if ANY key has been pressed down?
You can also use `Input.anyKeyDown()`
void Update()
{
if (Input.anyKeyDown())
{
DoSomething()
}
}
You could check for keyDown events in OnGUI: EventType, Event, EventType.KeyDown, event.type
So, I guess the code would look something like this (not tested):
public void OnGUI() {
if (Event.current.type == EventType.KeyDown) {
KeyPressedEventHandler();
}
}
private void KeyPressedEventHandler() {
// do whatever you want to do when a key was pressed ;-)
}
UnityScript / JavaScript would look almost the same - just replace "public void" with "function" and "private void" with "function" and it should compile in JavaScript/UnityScript ;-)
NOTE: In JavaScript, the proper syntax is:
function Update () {
if (Input.anyKeyDown) {
DoSomething();
}
}