Trying to figure out if one object can see another

I’ve got two objects in a scene. A spawn point and a player. I only want the spawn point to be active if the player can’t see it.

This is a bit of code I’m trying to use.

Ray ray = new Ray(transform.position, (transform.position - sm.currPlayer.transform.position).normalized);
RaycastHit hit;
			
if(Physics.Raycast(ray, out hit, 100.0f))
{
	if(hit.collider.gameObject.layer == 10) //If we hit a wall
	{
		Enemy z = Instantiate(e, transform.position, e.transform.rotation) as Enemy;
    }
}

The walls are all on layer 10. So my thinking is that we create a ray from the spawn point to the player. If it collides with one of these walls. That means the player likely can’t see the spawn point and go ahead and instantiate an enemy. Otherwise dont. But what is happening is that the enemy is spawning even the player is looking directly at the spawn point. Any help would be much appreciated.

Use Linecast instead of Raycast.