Dynamic Distance using Raycasting

Hi, I am new to this forum but have been tooling around with Unity for some time now. I have hit a snag building my game and was wondering if someone could help me. I have a view set up so that where the mouse is on the screen, the target is also there. I am trying to make it so that when the mouse/target is over a game object with a certain tag, it sets the distance of the target to the distance between the weapon and the game object. So if there are 2 game objects on screen, one at 50 units and the other at 100 units, when the mouse is over the object at 50 units the target is set at 50 units, same when it goes over the object at 100 units, the target will be set at 100 units. When no game object is there it is set at a fixed distance. This is how I am trying to do it but it is failing

var cannon : Transform;
var target : Transform;
function Update ()
{
//use mouse position to set target reticule based upon the fore camera
var screenPoint : Vector3 = Input.mousePosition;
//grab distance from ship to target
var tarDir : Vector3 = (target.position - cannon.position);
var hit : RaycastHit;
    var enemy : GameObject[] = gameObject.FindGameObjectsWithTag("enemy");
Physics.Raycast(cannon.position, tarDir, hit, tarDir.magnitude);
for(var en : GameObject in enemy)
{
    if(hit.collider && hit.collider.transform == en)
        {
            screenPoint.z = hit.distance;
        }
        else
        {
            screenPoint.z = 1000.0;
        }
 }

Debug.Log(hit.distance);

transform.position = Camera.current.ScreenToWorldPoint(screenPoint);

}

Am I going about this the wrong way, or what have I done wrong?

Thanks for the consideration, but I figured it out. Was using the wrong Raycast overload.

var cam : Camera;
var target : Transform;
var defaultDist : float = 2000.0;
function Update ()
{

//use mouse position to set target reticule based upon the fore camera
var screenPoint : Vector3 = Input.mousePosition;

//set z distance to a target if acquired, if not set to default distance
var hit : RaycastHit;
var ray : Ray = cam.current.ScreenPointToRay(screenPoint);
Physics.Raycast(ray, hit);
if(hit.collider && hit.collider.gameObject.FindGameObjectsWithTag("enemy"))
{
	screenPoint.z = hit.distance;
}
else
{
	screenPoint.z = defaultDist;
}

Debug.Log(screenPoint.z);

transform.position = Camera.current.ScreenToWorldPoint(screenPoint);

}