Astar Pathfinding with unity 2d

I am using Astar pathfinding in my 2d game but there is a problem.When an enemy follows the player and shoots after stopping at a particular distance from the player it doesn’t ee whether there is an object between between them and shoots directly at the obstacle.I want the enemy to move around the obstacle and shoot when there is no object between them.
I know we can use Raycast but I don’t know how to implement it…

You can have a bool called PlayerIsVisible, and if the player isn’t visible, you shouldn’t fire at the player. To check if the player is visible, you should fire a raycast in the direction of where the player is (player.transform.position - enemy.transform.position = direction) and if the raycastHit is equal to the player, the enemy can see the player without any obstacles blocking it, and so PlayerIsVisible equals true, else, it is false, and so you shouldn’t shoot, instead, go around the object and shoot again when the player is visible. @revanthpershad