Need help with ray cast

Hello all i was in the making of ai script and im going to make it that you can hid behind an object and the enemy wont be able to see you and to make him stop running untill his seen you again and i was just wondering how whould the best way of doing this be? and how whould i do it.

thank you in advance

When you use raycast from the enemy to the player, if the first object hit is the player, the enemy can see him, if it’s an obstacle, it can’t. Simple as that.