Switch keyboard to mouse controls

Hi, I have a game which can be played with the Keyboard, now I wanted to switch it using mouse controls, so I added a few boxes which function as HUD elements. What I want to achieve is that by pressing one of this elements it sents a movement command to the player like it does when pressing a keyboard key.

My code so far is:

function Update () {

if(Input.GetMouseButtonDown(0))

Debug.Log("Pressed left click."); 

}

Through the Debug.Log I see that the click is working, what I want to do now is say that the click on this button is identical to pressing “G key” on the keyboard.

So players have the option to either play the game with the keyboard or mouse by pressing certain UI buttons.

AFAIK there is no simple way to do this (unless it’s new with 3.5). What I’ve done in the past (I’ve run into the same issue), was to make a ‘HUDKey’ class which has a variable holding the key I’m looking for, and texture representing that key, which paints on the HUD. Clicking that does a SendMessage to the script where I do my input handling, and that sets a local var that says ‘this key was hit in the HUD’. Then the code like what you have becomes:

if (Input.GetKeyDown("G") || hudKeyHit == "G")
 ....

hudKeyHit = ""; // clear it out