I followed the incredibly helpful "Creating 2D Games in Unity 4.5" tutorial series and made my own little game that works perfectly. The main character has been programmed to move left and right when the "a" and "d" keys are pressed, respectively.

Here's my issue: I would like the main character to move in response to on-screen GUI buttons instead of just the "a" and "d" keys. So when I press an on-screen button, I need unity to "think" that the "a" key has been pressed. I've managed to get the Jump function to respond to an on screen button press by calling separate Jump function (shown at the very bottom of the script), but for some reason, moving left and right don't want to cooperate.

I'm a bit of a newbie when it comes to coding so forgive me if there's a simple solution that I'm unaware of. I appreciate any help!

Here's the chunk of code I'm dealing with:

public void HandleInput()
{

if (Input.GetKey (KeyCode.D))
{
Debug.Log ("Hello");

_normalizedHorizontalSpeed = 1;
if (!_isFacingRight)
Flip ();


}
else if (Input.GetKey (KeyCode.A))

{
_normalizedHorizontalSpeed = -1;
if (_isFacingRight)
Flip ();
}


else
{
_normalizedHorizontalSpeed = 0;
}



if (_controller.CanJump && Input.GetKeyDown (KeyCode.Space))
{
_controller.Jump ();
}


}


public void Jump()
{
if (_controller.CanJump)
_controller.Jump ();

}