You can use a Dictionary to map KeyCodeKeyCode to specific action, eventually you can change this at runtime:
using UnityEngine;
using System.Collections.Generic;
using System;
public class TestInput : MonoBehaviour {
private Dictionary<KeyCode,Action> d;
void Start ()
{
d = new Dictionary<KeyCode, Action>();
d[KeyCode.A] = () => {Debug.Log("ACTION A");};
d[KeyCode.S] = () => {Debug.Log("ACTION B");};
d[KeyCode.I] = () =>
{
Action swap = d[KeyCode.A];
d[KeyCode.A] = d[KeyCode.S];
d[KeyCode.S] = swap;
};
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.A))
{
d[KeyCode.A]();
}
else if (Input.GetKeyDown(KeyCode.S))
{
d[KeyCode.S]();
}
else if (Input.GetKeyDown(KeyCode.I))
{
d[KeyCode.I]();
}
}
}
Btw it seems that Unity does't expose any method that returns a list of all pressed keys, so the code above isn't very elegant. Hope this help.