Script to run when i press a certain key

New to scripting. But i need this script to run when i press a certain key, preferably “G”.

Try

    if(Input.GetKeyDown(KeyCode.G)) {
        // whatever
    }