Moving character with touch controls.

I am currently working on a 2D platformer and I am having issues with moving my character. I’ve exported this to Android as well. What I had originally were two separate buttons for movement back and forth using event triggers and that worked just fine. Well I was told to change that into one button so that the character can move back and forth without lifting your finger. Users should be able to move the character simply my moving their finger back and forth on the button. Any help on this issue is greatly appreciated.
Thank you!

Hi,

i have a mobile game where you can move the player by moving the finger over the screen not depending if you are on a button. The following snippet should do that.

private Vector3 velocity = Vector3.zero;
public float smoothTime = 0.3F;

void FixedUpdate ()
{
    Vector2 touchDeltaPosition = Vector2.zero;

    //touch movement
    if (Input.touchCount > 0)
    {
        // Get movement of the finger since last frame
        touchDeltaPosition = Input.GetTouch(0).deltaPosition * speed;
    }
    Vector3 actualPosition = GetComponent<Rigidbody2D>().position;
	Vector3 target = new Vector3(actualPosition.x + touchDeltaPosition.x, actualPosition.y + touchDeltaPosition.y, 0.0f);
	GetComponent<Rigidbody2D>().position = Vector3.SmoothDamp(actualPosition, target, ref velocity, smoothTime);
}

To make it work with your UI button you could use the following method. It simply checks if the pointer with the given id is over a gameObject.

http://docs.unity3d.com/ScriptReference/EventSystems.EventSystem.IsPointerOverGameObject.html

I didnt tested this but it should work.