If you both have the scene and game window open and the scene window shows the enemy, then
if (!target.GetComponentInChildren().isVisible)
{
continue;
}
does not work. You will still be able to face the enemy which is behind the camera if you press tab despite this code.
How could an open scene window affect the game during runtime?