how to convert keyboard controls into touch controls?

I am creating a 2d game that has the player move from left to right and the other way around on the ground. I am currently using this:

  if (Input.GetKey(moveLeft)) {
    rigidbody2D.velocity.x = 2;
   } else if (Input.GetKey(moveRight)) {
    rigidbody2D.velocity.x = -2;
   } else {
    rigidbody2D.velocity.x = 0;
   }

as code to move the object left and right. I’ve been googling a bit and found something about input.touch or so but nothing to get me going. I’d like some help on how to make this game so that when a player touches the object it will move along with the finger on the x axis. (so you can “slide” the object from left to right)

I am using this:

it converts keyboard, touch, joysticks, vita etc…

I found a solution:

	void Update () {
		if (Input.touchCount > 0) {
			// The screen has been touched so store the touch
			Touch touch = Input.GetTouch(0);
			
			if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved) {
				// If the finger is on the screen, move the object smoothly to the touch position
				Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10)); 
				touchPosition.y = transform.position.y;
				transform.position = Vector3.Lerp(transform.position, touchPosition, 20 * Time.deltaTime);
			}
		}

	
	}

This is the only script with which my object doesn’t disappear. If you wish to enable movement on the y axis as well just delete “touchPosition.y = transform.position.y;”
If you wish to increase the speed at which the object follows the touch just increase the number 20, for a lower speed you can ofcourse decrease the number.