Explosion damage only applied if enemy is visible

I am using this code to apply force and damage to objects:

#pragma strict

var blastRadius : float=20;

var blastDamage : float=100;

var blastForce : float=30;

function Start () {
    var objectsInRange : Collider[] = Physics.OverlapSphere(transform.position, blastRadius);    
    for (var col : Collider in objectsInRange)    {
    print(col.name+" in radius");
    var hit : RaycastHit;
    
    if(!Physics.Linecast(transform.position, col.transform.position, hit))
    {
var hidden=true;
    }
    else
    {
        print(col.name+" visible");
    var damage=blastDamage/hit.distance;
    col.transform.SendMessage("Damage", damage);
    if(col.transform.rigidbody){
    col.rigidbody.AddExplosionForce(blastForce, transform.position, blastRadius, 3.0);
    }
    }
    
}

It should only affect the object if the line from the explosion to the object is unbroken, but instead it affects everything in the radius. Please could someone tell me why, and how to fix it?
}

Your Physics.Linecast logic is wrong, plus you will always hit the collider of the game object with this logic. You can do:

if(Physics.Linecast(col.transform.position, transform.position, hit))

Or you could check the collider of the hit:

if(Physics.Linecast(transform.position, col.transform.position, hit) && hit.collider != col)