Enemy Raycast Not Working!

Hello. I am trying to make a raycast with my enemy to where once the player goes in his line of sight he begins to shoot. I have achieved this with a box collider trigger, but can’t figure out the raycast! I inserted a picture of the code I have so far. It is not working in that “Player in Sight” only happens once the player is actually touching the enemy (I have colliders on both the enemy and player, could that be affecting it?). Also, the enemy is still noticing the player even if the player is behind a wall. I am open to switching around layer masks but even when I tried to set one up (not pictured below) it still didn’t work. Please help!

    private void Update()
    {

        SpotPlayer(playerPos);
    }

    private void SpotPlayer (Transform playerPos)
    {

        if (Vector3.Distance(transform.position, playerPos.position) < viewDistance)
        {
            Vector3 directionToPlayer = (playerPos.position - transform.position - transform.position).normalized;
            float angleBetweenGuardAndPlayer = Vector3.Angle(transform.forward, directionToPlayer);
            if (angleBetweenGuardAndPlayer < fieldOfViewAngle / 2)
            {
                Debug.Log("viewAngle" + fieldOfViewAngle);

                foreach(RaycastHit hit in Physics.RaycastAll(transform.position, playerPos.position))
                {
                    Debug.Log(hit.collider.gameObject);
                }

                if (!Physics.Linecast(transform.position, playerPos.position)
                {
                    playerInSight = true;
                    nav.enabled = false;
                    Debug.Log("Player in Sight");
                }
            }
        }

        playerInSight = false;
        nav.enabled = true;
        Debug.Log("Player not in sight");
           
    }

Why reduce it twice

What @chengwang2077 said.

Also, given that you said both enemy and player have colliders, I don’t think Physics.Linecast(transform.position, playerPos.position) will ever return false unless the line lays entirely inside both colliders. That probably explains why it works when they are on top of one another. You should use a layermask that excludes both the player and the enemy. Remember we’re looking for obstacles between the player and the enemy.

Honestly I didn’t notice that, I will remove it, thank you for pointing it out!

It does return false when I first start the game, but it only returns true once they are on top of each other