Drag And Drop with Perspective Camera


When I have the mainCamera in Orthograpic view I have a working drag and drop “system” but when I change It to Perspective view the drag and drop code doesn’t work like It used to, and I need the Perspective view on the Camera.

So my question is:
Is It possible to have the camera on Perspective view and still have a working Drag and Drop “system” and how?


	void OnMouseDrag ()
			if (!assembledBL) { //Drag the hexKey with mouse
				point = Camera.main.ScreenToWorldPoint (Input.mousePosition);
				point.y = transform.position.y;
				transform.position = point;
			} else if (assembledBL) { // twist the hexKey
				xScroll = Input.GetAxis ("Mouse ScrollWheel");
				this.transform.Rotate (xScroll * 10f, 0f, 0f);


You have to provide the z position when calling ScreenToWorld point:

point = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Camera.main.nearClipPlane))

Now you’ll have world position that is at your clipping plane of the camera (i.e. on the display so to speak). In a coordinate system where x and y define the screen space and z is the depth you would then change the x and y position of your transform based on this world position (point) but keep its z position like so:

transform.position = new Vector3(point.x, point.y, transform.position.z);

If your coordinate system is different then change this accordingly.