detecting enemy near to player

my need is when enemy reach 5 cm near to player his health should reduce. how to calculate whether the enemy has reached 5 cm near to the player

var dist: float = Vector3.Distance(player.transform.position, target.transform.position);
if (dist < damageDist){
hitpoints -= damagePerSecond * Time.deltaTime;
}

or (because it doesn’t use square roots —> faster)

var distVec: Vector3 =  player.transform.position - target.transform.position;
var distSqr: float = distVec.sqrMagnitude;
if (distSqr < damageDist * damageDist){
    // same as other one
}