Camera movement on background

So i have a big 2D sprite picture and now i can move my camera as much as i want on X-axis. But how to stop movement when sprite is ended?

35239-untitled.png

public class MoveCamera : MonoBehaviour {

public float mouseSensitivity  = 0.025f;
private Vector3 lastPosition;
public Transform background;

void Update()
{
	if (Input.GetMouseButtonDown(0))
	{
		lastPosition = Input.mousePosition;
	}
	if (Input.GetMouseButton(0))
	{
		bounds = new Bounds();
		Vector3 delta = Input.mousePosition - lastPosition;
		transform.Translate(delta.x * mouseSensitivity, 0, 0);

		lastPosition = Input.mousePosition;

	}

}

}

In order to know where to stop movement you first need to know the width of your sprite in Unity units, just select your sprite and on the inpector check the value of Pixels to Units, should be 100 is you haven’t changed it, divide the number of pixes on you sprite by that number and that will give you the width of your sprite in Unity units. You also need to know how much of your sprite the camera is viewing, thats easy to find out if you are using a 2D camera, first find the screen’s aspect ratio by dividing the Screen.width by the Screen.height, then divide the camera.orthographicSize by the aspect ratio, and that will tell you how many Unity units can your camera view from the center to either side (left or right), if you multiply that number by 2 you’ll know the total number of Unity units you camera can view on the X axis.

With that in mind, the math to find out where to stop movement should be quite simple, just stop moving when the left border of the camera reaches the left border of your sprite, do the same with the right side and that’s all.