How to turn off flashlight when enemy is near us

Hello, I would like to know if is possible this. My scene is like this, Im walking inside a house with a flashlight and in one of the rooms there is an enemy so my question is, how I can turn of the flashlight when the enemy is near me so the flashlight is not so intense in the enemy?

Basically is like the enemy turn off our flashlight and when we are at certain distance the flashligh works again.

Thanks.
Seba.

Answered here:

Hi Everynone, thanks! I solved in a similar way.