How to use GUI.HorizontalScrollbar to move the camera left to right

For a 2D Side Scrolling game I want to implement a horizontal scroll bar that controls the camera position from left to right, however i’m not sure how to setup the horizontal scroll bar. Do I need to add a GUI component to the main camera and add the script to the camera? Below is some code that I thought might be helpful but am unsure how to make it work for a 2D side scrolling game.

using UnityEngine;
using System.Collections;

[AddComponentMenu("Camera-Control/Mouse Orbit with zoom")]
public class OrbitCamWithXOffset: MonoBehaviour
{
public Transform target;
public float zoomMultiplier = 1.2f;
public float distance = 0.0f;
public float xSpeed = 45.0f;
public float ySpeed = 45.0f;
public float rotLeftMax = 135f;
public float rotRightMax = 210f;
public float distanceMin = 1.2f;
public float distanceMax = 2.0f;
public Rect camSliderRect;
 
private float hSliderValue = 10f;
private float x = 0.0f;
private float y = 0.0f;
private bool camRotLeft = false;
private bool camRotRight = false;
 
 
// Use this for initialization.
void Start (){
Vector3 angles = transform.eulerAngles;
x = angles.y;
y = angles.x;
 
// Make the rigid body not change rotation.
if (rigidbody)
rigidbody.freezeRotation = true;
}
 
void OnGUI(){
camSliderRect = new Rect(10,10,200,40);
hSliderValue = GUI.HorizontalScrollbar(camSliderRect, x, 1, rotLeftMax, rotRightMax);
}
 
void LateUpdate (){
if (target && Input.GetMouseButton(0)) {
x += Input.GetAxis ("Mouse X") * xSpeed * distance * 0.02f;
x = ClampAngle (x, rotLeftMax, rotRightMax);
 
Quaternion rotation = Quaternion.Euler (y, x, 0);
distance = Mathf.Clamp (distance - Input.GetAxis ("Mouse ScrollWheel") * zoomMultiplier, distanceMin, distanceMax);
 
Vector3 negDistance = new Vector3 (0.0f, 0.0f, -distance);
Vector3 position = rotation * negDistance + target.position;
 
transform.rotation = rotation;
transform.position = position;
}
}
 
// Clamp angle to 360 degrees.
public static float ClampAngle (float angle, float min, float max){
if (angle < -360f)
angle += 360f;
if (angle > 360f)
angle -= 360f;
return Mathf.Clamp (angle, min, max);
}
}

maybe this can help you:

using UnityEngine;
using System.Collections;

public class MoveCameraWithScrollBar : MonoBehaviour {
	
	float barValue; //value, in pixels, of where is the scrollbar
	float barHeight; //the total value where the scrollbar can travel
	float posZCamera; //the position of the camera, read once only
	
	void Start () 
	{
		posZCamera = Camera.main.transform.position.z; //init the z position of the camera
		barHeight = 2048; //init a value for the limit of the bar (can be dynamic)
	}
	
	void Update () 
	{
		//a new vector that depends of screen pixels, for horizontal movement change valueBar to x component and put Screen.height in y component
		Vector3 currentPos = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width/2,barValue,posZCamera));
		//move the object, you are moving the camera in function of the same camera, so you need to center
		//dividing by 2 because 0,0 of the screen is different that camera pos
		transform.position = new Vector3(currentPos.x/2, currentPos.y/2, currentPos.z/2);
		print(barValue);
		print(transform.position);
	}
	
	void OnGUI()
	{
		//obtain the value of the position of the bar in pixels, so you can use it for change the camera position
		barValue = GUI.VerticalScrollbar(new Rect(0,0,Screen.width*0.01f,Screen.height), barValue, Screen.height*0.2f, 0.0f, barHeight);
	}
}