How to get the enemy AI to run away when hit by light component?

I am trying to develop a horror game, I have created the enemy AI so when the player walks in front it will follow, but I also want the player to be able to shine its flashlight on the enemy causing it to either run away or play animation, I’ve tried everything I can think of to get it to work. Just wondered if anybody had a working idea of how to do it, that would be great.

use physics.Raycast