How do I determine how well lit something is?

I’m making a scary game, and there is 0 ambient light. The only light in the game comes from lights created and thrown by the player. I have enemies that only attack when they can be seen. Right now they only attack if the player is looking at them, but I want them to only attack if the player is looking at them AND they aren’t shrouded in 100% blackness.

C# preferred :slight_smile:

EDIT:
I checked out the questions commented below, and came up with the following, but it doesn’t work!

		//Determine if the monster is visible
		List<Ray> LightRays = new List<Ray>();
			
		GameObject[] playerlights = GameObject.FindGameObjectsWithTag("PlayerLight");
		
		for (int i = 0; i<playerlights.Length; ++i){
			LightRays.Add(new Ray(transform.position, playerlights*.transform.position));*

Debug.DrawLine(LightRays_.origin, playerlights*.transform.position);
}*_

* for (int i = 0; i<LightRays.Count; ++i){*
_ if (Physics.Raycast(LightRays*, out result)){
//if the raycast hit something
if (result.distance <= playerlights.GetComponentInChildren().range && result.transform == playerlights.transform){
//and the distance between things is less than the light’s range and the other thing is that light*

* islit = true;
}
}
print(result.transform.tag);
}*_

* if (islit)*
* print (“LIT”);*
* else*
* print (“NOT LIT”);*
I have checked, and this program does cast a ray to each and every PlayerLight in the scene. This code always states that the monster is NOT lit. However, if I remove the line:
“&& result.transform == playerlights*.transform”*
Then it always states that is IS lit. Whether or not it is actually lit seems irrelevant.
Any suggestions?

Why not just check how close to a light source you are, if you found a distance that you considered fully lit you could use that instead of how light they are.

I combined several solutions.

Firstly I raycasted between the player and the monster to determine if there was a clear line of sight. Then, i detected if the player was rotated in such a way so that the monster is within his range of vision. Then finally, i added spherical trigger colliders around each of the throwable lights, and scaled them to match. If all of those things return true, then the monster can be seen :smiley: