Lock object's movement to one axis

I’m making a scaleable cube, on the xyz faces there are handles which when dragged scale the central cube.

Using the below code works on the X(red) handle and with slight changes on the Y(green) handle.

import UnityEngine;
import System.Collections;
var screenPoint : Vector3;
var offset         : Vector3;
var scalingCube    : GameObject;
var clipBounds    : Vector2;

function OnMouseDown()
{   
        screenPoint = Camera.main.WorldToScreenPoint(this.transform.position);
        offset = this.transform.position - Camera.main.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, 0));
}

function OnMouseDrag()
{
        var curScreenPoint  : Vector3 =  Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
        var curPosition     : Vector3 = Camera.main.ScreenToWorldPoint(curScreenPoint)+ offset;
       
        curPosition.x = Mathf.Clamp(curPosition.x, clipBounds.y, clipBounds.x);    //clip the movement to a usable range
       
        this.transform.position.x = curPosition.x;    // move the handle
       
        scalingCube.transform.localScale.x = (this.transform.localPosition.x * -2); // scale the centre cube

}

However I’m having trouble getting it working on the Z handle, I think it’s something to with moving the mouse to the right, I’ve altered to code to what’s below which almost works the only problem is when I click the handle it automatically jumps back to 0. (Note the -'s in front on Input.mousePosition.x’s)

import UnityEngine;
import System.Collections;


var screenPoint : Vector3;
var offset         : Vector3;
var clipBounds    : Vector2;
var scalingCube    : GameObject;

function OnMouseDown()
{   
        screenPoint = Camera.main.WorldToScreenPoint(this.transform.position);
        offset = scalingCube.transform.position - Camera.main.ScreenToWorldPoint(Vector3(-Input.mousePosition.x, Input.mousePosition.y, 0));
}

function OnMouseDrag()
{
        var curScreenPoint  : Vector3 =  Vector3(-Input.mousePosition.x, Input.mousePosition.y, 0);
        var curPosition     : Vector3 = Camera.main.ScreenToWorldPoint(curScreenPoint)+ offset;

        curPosition.x = Mathf.Clamp(curPosition.x, clipBounds.y, clipBounds.x);    //clamp the movement to a usable range
        this.transform.position.z = curPosition.x;                                    //set the handles position
       
        scalingCube.transform.localScale.z = (this.transform.localPosition.z * -2); // -2 as we're scaling out the back of z
}

I guess it’s just one simple thing Im missing but have been staring at it for so long the codes turned to mush, any help would be much appreciated.

function OnMouseDown()
{
    screenPoint = Camera.main.WorldToScreenPoint (this.transform.position);
    offset = this.transform.position - Camera.main.ScreenToWorldPoint ( Vector3 (Input.mousePosition.x, Input.mousePosition.y, screenPoint.z));
}

function OnMouseDrag()
{
    var curScreenPoint  : Vector3 = Camera.main.ScreenToWorldPoint (new Vector3 (Input.mousePosition.x,
                                                                                   Input.mousePosition.y,
                                                                                  screenPoint.z));
    var curPosition : Vector3 = new Vector3(curScreenPoint.x,
                                              curScreenPoint.y,
                                              curScreenPoint.z + offset.z);
   
    curPosition.z = Mathf.Clamp(curPosition.z, clipBounds.y, clipBounds.x);    //clamp the movement to a usable range                                             
                                                                                                                                             
    this.transform.position = new Vector3(transform.position.x, transform.position.y, curPosition.z);
   
    scalingCube.transform.localScale.z = (this.transform.localPosition.z * -2.0);
}

taken from unity game engine - Unity3d drag an object with finger problems - Stack Overflow which is where i must have got the original code from.