Your function won't ever get called if the mouse is "next to" the object, even if the distance is less than your "maxBlockDist" variable, because you have placed it in the "OnMouseEnter" function, so the mouse has to actually be over the object before the code can run at all. When the mouse is only next to the object, the code isn't even doing that distance check.
If you want to run some code when the mouse is near an object, you'll need to compare the object's position on-screen to the mouse's screen coordinates every frame - something like this:
var proximityRequired = 50
var overColor : Color;
var nearColor : Color;
var withinRange = false;
function Update() {
var screenPos = camera.WorldToScreenPoint(transform.position);
var mousePos = Input.mousePosition;
var proximity = (screenPos-mousePos).magnitude;
if (proximity < proximityRequired) {
renderer.material.color = nearColor;
if (!withinRange) {
withinRange = true;
FunctionToCallWhenRangeEntered();
}
} else {
renderer.material.color = normalColor;
withinRange = true;
}
}
It might have happened because some or the objects ou attached the script to does not have a collider. Another eeason might be because your collider was not hit because it was too small or cover by some other collider. Attaching this scrit to the player also does not work.
It seems Vector3.Distance was not the problem, it was the fact that my first person controller's position never changes, even though I freely move it around. So that's the source problem.