Using a "Flashlight" as a form of Detection

Hello Unity Community,

I have been working with Unity for a little while, and have ran into a problem. I want to make a quick example of a “stealth”, the basis of the game is that the enemies can only detect you if you are in their flashlight sight. After researching I found out that Sphere casting would be the best way to do this. However, I found none of the documentation helpful, and after looking at other examples I am still stumped on how to “detect” of the block is in the flashlight area.

Any help is greatly appreciated!

alt text

I just figured it out actually, thanks anyways for the comments (well I actually stole concepts and pieces of code from other places). If anyone has an easier more robust way I would be glad to hear it!

public var radius = 1.0f;
public var distance = 10.0f;
	
function Start () {

}

function Update () {

		var forwardRay = new Ray(transform.position, transform.forward);
		var hits = Physics.SphereCastAll(forwardRay, radius, distance);
	
		Debug.DrawRay(forwardRay.origin, forwardRay.direction * distance, Color.white);	
		for (var hit in hits)
		{
			Debug.DrawLine(forwardRay.origin, hit.point, Color.red);
			Debug.DrawRay(hit.point, hit.normal, Color.blue);
			
			if (hit.collider.tag == "Player")
				print("player detected");
		}
}