Camera only panning on 1 axis

Hello before i continue here is a WebPlayer Example

Zoom in with Scroll Wheel
Pan around by holding right mouse button and moving mouse.

I am trying to make a world map that can be zoomed into and panned around, I have managed to add the zooming and left to right panning but for some reason it will not pan up and down,

The camera is top down orthographic so i would need to get the X and Z correct?

Here is what i have got so far, Any pointers or hints would be greatly appreciated thanks.

using UnityEngine;
using System.Collections;

public class DragCamera : MonoBehaviour
{
	public float dragSpeed = 2;
	private Vector3 dragOrigin;
	
	public bool cameraDragging = true;
	
	public float outerLeft = -1000f;
	public float outerRight = 1000f;
	public float outerUp = -1000f;
	public float outerDown = 1000f;

	public float zoomSpeed = 1000;

	Camera cam;

	void Start(){
		cam = this.camera;
	}
	
	void Update()
	{
		if (outerLeft > 0)
			outerLeft = 0;
		if (outerLeft < -19800)
			outerLeft = -19800;

		if (outerRight < 0)
			outerRight = 0;
		if (outerRight > 19800)
			outerRight = 19800;

		if (cam.orthographicSize > 20000)
			cam.orthographicSize = 20000;
		if (cam.orthographicSize < 200)
			cam.orthographicSize = 200;

		
		Vector3 mousePosition = new Vector3 (Input.mousePosition.x, Input.mousePosition.z);
		
		float left = Screen.width * 0.2f;
		float right = Screen.width - (Screen.width * 0.2f);
		float up = Screen.height * 0.2f;
		float down = Screen.height - (Screen.height * 0.2f);
		
		if (mousePosition.x < left) {
			cameraDragging = true;
		}else 
		if(mousePosition.x > right) {
			cameraDragging = true;
		}
		if (mousePosition.z < up) {
			cameraDragging = true;
		}else 
		if (mousePosition.z > down) {
			cameraDragging = true;
		}
		if (Input.GetKey (KeyCode.KeypadPlus) || Input.GetAxis("Mouse ScrollWheel") > 0) {
			cam.orthographicSize -= zoomSpeed;
			outerLeft -= zoomSpeed;
			outerRight += zoomSpeed;
		}
		if (Input.GetKey (KeyCode.KeypadMinus) || Input.GetAxis("Mouse ScrollWheel") < 0) {
			cam.orthographicSize += zoomSpeed;
			outerLeft += zoomSpeed;
			outerRight -= zoomSpeed;
		}
		
		
		
		
		
		if (cameraDragging) {
			
			if (Input.GetMouseButtonDown (1)) {
				dragOrigin = Input.mousePosition;
				return;
			}
			
			if (!Input.GetMouseButton (1))
				return;
			
				Vector3 pos = Camera.main.ScreenToViewportPoint (Input.mousePosition - dragOrigin);
				Vector3 move = new Vector3 (pos.x * dragSpeed, 0, 0);
			
			if (move.x > 0f) {
				if (this.transform.position.x < outerRight) {
				transform.Translate (move, Space.World);
				}
			}else{
				if (this.transform.position.x > outerLeft) {
				transform.Translate (move, Space.World);
				}
			}	

			if (!Input.GetMouseButton (1))
				return;
				
				Vector3 pos2 = Camera.main.ScreenToViewportPoint (Input.mousePosition - dragOrigin);
				Vector3 move2 = new Vector3 (pos2.z * dragSpeed, 0, 0);
				
			if (move2.z > 0f) {
				if (this.transform.position.z < outerDown) {
					transform.Translate (move2, Space.World);
				}
			}else{
				if (this.transform.position.z > outerUp) {
					transform.Translate (move2, Space.World);
				}

			}
		}
	}
}

I think there are much better ways of doing this, here’s a quick example of how I might go about it:

public float dragSpeed = 2;
Vector3 dragOrigin;

public bool cameraDragging = false;

public float outerLeft = -1000f;
public float outerRight = 1000f;
public float outerDown = -1000f;
public float outerUp = 1000f;

public float zoomSpeed = 100;
Vector3 dir;

Camera cam;
Transform trans;

void Start(){
	cam = this.camera;
	trans = this.transform;
	Clamp();
}

void Update(){
	if(Input.GetKey(KeyCode.KeypadPlus) || Input.GetAxis("Mouse ScrollWheel") > 0) {
		cam.orthographicSize -= zoomSpeed;
		outerLeft -= zoomSpeed;
		outerRight += zoomSpeed;
		outerDown -= zoomSpeed;
		outerUp += zoomSpeed;
		Clamp();
	}else if(Input.GetKey(KeyCode.KeypadMinus) || Input.GetAxis("Mouse ScrollWheel") < 0) {
		cam.orthographicSize += zoomSpeed;
		outerLeft += zoomSpeed;
		outerRight -= zoomSpeed;
		outerDown += zoomSpeed;
		outerUp -= zoomSpeed;
		Clamp();
	}

	if(Input.GetMouseButtonDown(1)){
		dragOrigin = Input.mousePosition;
		cameraDragging = true;
	}
	if(Input.GetMouseButtonUp(1)){
		cameraDragging = false;
	}
	if(cameraDragging){
		dir = cam.ScreenToViewportPoint(Input.mousePosition - dragOrigin);
		Vector3 pos = trans.position;
		pos += (trans.up*dir.y + trans.right*dir.x)*dragSpeed;
		pos.x = Mathf.Clamp(pos.x, outerLeft, outerRight);
		pos.z = Mathf.Clamp(pos.z, outerDown, outerUp);
		trans.position = pos;
		
	}
}

void Clamp(){
	cam.orthographicSize = Mathf.Clamp(cam.orthographicSize, 1, 20000);
	outerLeft = Mathf.Clamp(outerLeft, -19800, 0);
	outerRight = Mathf.Clamp(outerRight, 0, 19800);
	outerDown = Mathf.Clamp(outerDown, -19800, 0);
	outerUp = Mathf.Clamp(outerUp, 0, 19800);
}

Hope that helps!

Scribe