I need help with an AI

So i have a maze with an AI that walks around the maze and when it sees the player it starts chasing the player but the problem is that the AI sees the player trough walls and i don’t understand why because i tried a lot of methods and none worked

Here is the script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class MazeAI : MonoBehaviour 
{
    GameObject player;

    public NavMeshAgent agent;
    public float range; 

    public Transform centrePoint;

    [SerializeField] float sightRange;
    bool playerInSight;

    [SerializeField] LayerMask playerLayer;

    void Start()
    {
        agent = GetComponent<NavMeshAgent>();
        player = GameObject.Find("Player");
    }


    void Update()
    {
        if (agent.remainingDistance <= agent.stoppingDistance) 
        {
            Vector3 point;
            if (RandomPoint(centrePoint.position, range, out point)) 
            {
                Debug.DrawRay(point, Vector3.up, Color.blue, 1.0f); 
                agent.SetDestination(point);
            }
        }


        {
            playerInSight = Physics.Raycast(transform.position, transform.TransformDirection (Vector3.forward),out RaycastHit hitinfo, 20f, playerLayer);
            Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * hitinfo.distance, Color.red);     
        }
        if (playerInSight) Chase();
    }
    bool RandomPoint(Vector3 center, float range, out Vector3 result)
    {

        Vector3 randomPoint = center + Random.insideUnitSphere * range;
        NavMeshHit hit;
        if (NavMesh.SamplePosition(randomPoint, out hit, 1.0f, NavMesh.AllAreas))
        {
            result = hit.position;
            return true;
        }

        result = Vector3.zero;
        return false;
    }

    void Chase()
    {
        agent.SetDestination(player.transform.position);
    }

}

Does you layer mask also include the layer of the walls?