Use MIDI instruments as game controllers!
This Unity interface allows you to map MIDI inputs to keyboard buttons - play the mapped input on your instrument to trigger the corresponding key press.
The interface currently supports GetKey
, GetKeyDown
and GetKeyUp
events for all keyboard buttons.
Direct button presses (i.e., using the keyboard rather than a mapped instrument) will still be detected.
UnityMidiControl was tested on Unity version 4.6.2f1 and is known to cause crashes on Unity version 4.6.1f1.
- Import keijiro's MIDI Jack into your Unity project
- Copy the appropriate .dll from
MidiJack/Plugins/
to the root folder of your Unity project - Copy the contents of Assets into the Assets folder of your project
- In Unity, click MIDI Input > Edit Key Mappings to open the editor GUI
- Add key mappings as desired
- mappings can be removed using the '-' buttons
- Click Save Mappings
- In your game code, replace calls to
Input.GetKey
,Input.GetKeyDown
andInput.GetKeyUp
withUnityMidiControl.Input.InputManager.GetKey
,UnityMidiControl.Input.InputManager.GetKeyDown
andUnityMidiControl.Input.InputManager.GetKeyUp
, respectively - Before running your project, ensure your MIDI device is connected
The following note mappings trigger:
- the 'x' key when note number 36 is played on any MIDI channel
- the 'd' key when note number 50 is played on MIDI channel 8
- the 'a' key when a control knob on channel 22 has a value between 3 (exclusive) and 75 (inclusive) on any MIDI channel
- the 'b' key when a control knob on channel 31 has a value between 50 (exclusive) and 100 (inclusive) on MIDI channel 3
These keypresses may be detected programmatically using the following code:
if (UnityMidiControl.Input.InputManager.GetKeyDown("x")) {
Debug.Log("'x' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("d")) {
Debug.Log("'d' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("a")) {
Debug.Log("'a' down");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown("b")) {
Debug.Log("'b' down");
}
Using key codes rather than string arguments will also work:
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.X)) {
Debug.Log("'x' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.D)) {
Debug.Log("'d' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyUp(KeyCode.A)) {
Debug.Log("'a' up");
}
if (UnityMidiControl.Input.InputManager.GetKeyDown(Keycode.B)) {
Debug.Log("'b' down");
}