How to make an Enemy ai run away from the players flashlight?

How to make an enemy ai run away when it gets hit by the player flashlight? I have an flashlight script with batteries and I want the enemy to run away if it get’s hit by a light component is there a function for this like a check to see if there is a spotlight infront if you or do I have to use a raycast? If it’s with ray casts could you helm me a little bit because I have never used raycast I mainly use projectiles?

I would use raycast , but you can also put an invisible cone on the flashlight and have it a triggerCollider to sense when enemy is in cone. Or a trigger collider on the enemy ( maybe better) that senses when cone is on him