String as a input

I’m trying to make a public variable “button” and later use it as a input key. for testing purposes, I would like to be able to change string in the inspector that I want to press as the input. I’/m pretty new to scripting, and trying to learn some c#. I tried something like this:

public string button = “”;

void Update () {

    if (Input.GetKeyDown (KeyCode.button)) {
    resetCubes();
    }

}

that is not working at all, unity says that there is no definition “button” for a keyCode

You can’t do that. You can look at the the doc for valid keyCode but you can’t make it dynamic in this way.

Instead of string, it should be of type KeyCode. For example:

public KeyCode button = KeyCode.W;

//...(somewhere else in your code, you can change button..)
button = KeyCode.L;