Mouse drag on X, Z axes?

Hi all, i’m newie on js scripting. I try to apply script in to game object to move on 2d X and Z axes.
For to do that y follow a flasdevelop tutorial with this example code:

function Update () {
}

var screenSpace;
var offset;

function OnMouseDown(){
	//translate the cubes position from the world to Screen Point
	screenSpace = Camera.main.WorldToScreenPoint(transform.position);
	 
	//calculate any difference between the cubes world position and the mouses Screen position converted to a world point  
	offset = transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x,Input.mousePosition.y, screenSpace.z));
	
}

/*
OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.
OnMouseDrag is called every frame while the mouse is down.
*/

function OnMouseDrag () {

	//keep track of the mouse position
	var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);     

	//convert the screen mouse position to world point and adjust with offset
	var curPosition = Camera.main.ScreenToWorldPoint(curScreenSpace) + offset;

	//update the position of the object in the world
	transform.position = curPosition;
     
}

The code only move my object on X,Y axes :S.

How can i modify this code to move with drag mouse on X and Z axes?

Thanks
Sorry my bad english.

Hello!

I think your problem resides here :stuck_out_tongue:

var curScreenSpace = Vector3(Input.mousePosition.x, Input.mousePosition.y, screenSpace.z);