Detecting if a wall is blocking 'visibility'

I’m trying to have an enemy in my game disappear after being looked at.

The script itself is basic right now, and during testing I ran into a problem: the object is still ‘visible’ when behind a wall I made. I understand that the engine still has to render the object behind the wall, but I’m wondering if theirs a quick fix for this.

using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Security.Cryptography;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.UIElements;

public class eye_reciever : MonoBehaviour
{
    public float vis_time = 2f;
    bool shy;
    float start;

    // Start is called before the first frame update
    void Start()
    {
        start = Random.Range(0, 1);
        if (start != 0)
        {
            shy = false;
            UnityEngine.Debug.Log("I'm not shy from begining!");
        }
        else
        {
            shy = true;
            UnityEngine.Debug.Log("I'm shy from beginning!");
        }
    }

    // Update is called once per frame
    void Update()
    {
        if (GetComponent<Renderer>().isVisible == true && shy == false)
        {
            vis_time -= Time.deltaTime;   
            if(vis_time <= 0)
            {
                shy = true;
                UnityEngine.Debug.Log("I'm shy from vis_time = 0!");
                GetComponent<Renderer>().enabled = false; 
                GetComponent<BoxCollider>().enabled = false;
              // GetComponent<Transform>().localPosition = Vector3.zero; [Get it to teleport, either randomly or at set locations. Idk]
            } 
        }
        else if(GetComponent<Renderer>().isVisible == false && shy == false)
        {
            vis_time += Time.deltaTime;
        }         
        if (GetComponent<Renderer>().enabled == false)
        {
            vis_time += Time.deltaTime;  
        }    
        if (vis_time >= 4f)
        {
            shy = false;
            UnityEngine.Debug.Log("I'm not shy from vis_time replenishing!");
            GetComponent<Renderer>().enabled = true;
            GetComponent<BoxCollider>().enabled = true;
        }
    }

}

Any help would be greatly appreciated!

You need a better way to detect visibility, Renderer.isVisible leaves room for it to behave not the way you want, this is what Unity says in the documentation:

Note that the object is considered visible when it needs to be rendered in the Scene. For example, it might not actually be visible by any camera but still need to be rendered for shadows. When running in the editor, the Scene view cameras will also cause this value to be true.

You need a Field of View system like this:
Field of view visualisation (E01) - YouTube
It’s much more reliable than Unity’s Renderer.isVisible.