distance to object + mouse aiming

ok its late and it might be because i’m tired that i dont get this but i’m having some trouble with distance detection.
i am currently using the mouse look script and “Screen.lockCursor = true;” command to center the mouse. i can set it up so that when i mouse over / aim at the object it changes a color but i want it to change when i am at a certain distance away from the object. this is what i have pieced together from several sources and attempted to add in a distance calculator

var dist;

var vector;
function FixedUpdate ()
{
var dist = GameObject.FindWithTag(“Player”).transform.position - transform.position;
dist.y = 0;
vector = dist.magnitude;
}

function OnMouseEnter()
{
if (vector <= .5 )
{
renderer.material.color = Color.black;
}

else
{
}
}
i have a version of my game hosted at my site [http://www.hazardousproductions.net/Testing/Testing.html][1]

with this code in there (the look and highlight command)
var dist;
var vector;
function FixedUpdate ()
{
var dist = GameObject.FindWithTag(“Player”).transform.position - transform.position;
dist.y = 0;
vector = dist.magnitude;
}

function OnMouseEnter()
{
renderer.material.color = Color.black;
}

function OnMouseExit()
{
renderer.material.color = Color.black;
}

thanks in advance

note:

in the game use the mouse to look around
w a s d or arrow keys to walk around
and the level the problem is on is level 1

Raycast should do the trick:

var RaycastToCenterHit : RaycastHit;
var cameraTransformRaycast : Transform = Camera.main.transform;
Physics.Raycast(cameraTransformRaycast.position, cameraTransformRaycast.TransformDirection(Vector3.forward), RaycastToCenterHit);
if (RaycastToCenterHit.distance <= minimalDistance){
//Color the switch
}

i was over thinking the whole thing lol. i used raycast to detect the distance from the object and ditched the mouseenter idea because it wasnt working out correctly. my somewhat final code

   var dist;
var close;


function Update ()
{
dist = transform.TransformDirection (- Vector3.forward);

if (Physics.Raycast (transform.position, dist, 1))
{
close = 1;
renderer.material.color = Color.black;
}
else
{
close = 0;
renderer.material.color = Color.white;
}
if(Input.GetButton("Use"))
{
if ( close > 0)
{
renderer.material.color = Color.green;
}
}
}