Raycast not working properly

I'm trying to create a raycast for my enemy so if the player is behind a wall, the enemy will not attack...this is what im currently using inside my update function:

var dist = lookAtTarget.position - transform.position;

var hit : RaycastHit;
if(Physics.Raycast(transform.position, dist,hit))
{
    if(hit.collider.CompareTag("Player"))
    {
        Attack();
    }
    else
    {
        return false;
    }

        Debug.DrawLine (transform.position, hit.point);
}

The problem im having is that when i play the game, if the player is in range of the enemy but standing still, the enemy will not attack...but if i start moving, thats when the enemy starts to attack...All im trying to get accomplished is to have the enemy disengage when the player is either behind a wall or out of range with the use of raycast...I also tried using linecast and i was getting the same result...

You make the call to Physics.Raycast() outside of any function. I think you should move it to Update() to let the enemy constantly check for the player instead of just once. Still I can't explain why the enemy starts to attack when the player moves.

if(Physics.Raycast(transform.position, dist*1.1,hit))

untested