using UnityEngine;
using System.Collections;

public class Paulwrap : MonoBehaviour {



	public Camera cam;
	Vector2 luPara;
	Vector2 roPara;

	// Use this for initialization
	void Start () {
		cam = GameObject.FindWithTag("MainCamera").camera;
		luPara =  new Vector2(cam.ScreenToWorldPoint(new Vector3(0,0,cam.nearClipPlane)).x, cam.ScreenToWorldPoint(new Vector3 (0,0,cam.nearClipPlane)).y);
		roPara = new Vector2(cam.ScreenToWorldPoint(new Vector3 (cam.pixelWidth,cam.pixelHeight,cam.nearClipPlane)).x, cam.ScreenToWorldPoint(new Vector3(cam.pixelWidth,cam.pixelHeight,cam.nearClipPlane)).y);

	}
	
	// Update is called once per frame
	void Update () {

		wrap ();
	}

	void wrap () {
		if (transform.position.x <= luPara.x){
			transform.position = new Vector3(roPara.x - 0.01f, transform.position.y, transform.position.z);
		}
		if (transform.position.x >= roPara.x){
			transform.position = new Vector3(luPara.x, transform.position.y, transform.position.z);
		}
		if (transform.position.y <= luPara.y){
			transform.position = new Vector3(transform.position.x, roPara.y -0.01f, transform.position.z);
		}
		if (transform.position.y >= roPara.y){
			transform.position = new Vector3(transform.position.x, luPara.y, transform.position.z);
		}
	}


}
