2d(mouse) distance from a 3d object

    var mouseX = 0;

function Update() 
{ 
  mouseX = 90 * ((Input.mousePosition.x - Screen.width / 2) / (Screen.width / 2)); 
}

this code works on a distance from the centre of the screen. how to work on a distance from a perticular 3d object (that can also move through screen, on runtime)?

I would check the mouse position when it goes over the object, but the mouse doesn't have to pass over the object. it just needs to know what's the mouse X and Y distance from the object.

What ideas would you come up with?

Try:

DistanceFromMyObjectToMouseInPixels = 
    Vector3.Magnitude(Camera.main.WorldToScreenPoint(MyObject.transform.position) - Input.mousePosition);

Hope I understand what you're trying to do correctly...

Your question is so hard to understand. Please rephrase.

If I get your meaning, you are asking for the distance in pixels of the mouse and some object. To do this, you would use Camera.WorldToScreenPoint.

var target : transform;

function Update() {
    var distance : float = (Input.mousePosition - camera.WorldToScreenPoint(target.position)).magnitude;
}