enemy's line of sight

I know this is probally simple but how can I add in a max distance of the enemy’s line of sight. So that if I’m within a certain angle and a certain distance the enemy can see me. And two, I have two debug.drawray that draws an angle to represent its angle sight view. So how can I connect both end-points of each line so it become a cone?

Vector3 rayDirection = player.transform.position - transform.position;
		
		// Detect if player is within the field of view
		if((Vector3.Angle(rayDirection, transform.forward)) < fieldOfViewRange)
		{ 
			if (Physics.Raycast (transform.position, rayDirection, out hit)) 
			{
				if (hit.transform.tag == "Player") 
				{
					//GetComponent<NavMeshAgent>().destination = player.position;
					renderer.material.color = Color.yellow;
					//Debug.Log("Can see player");
					isAlterted = true;
				}
			}

It’s quite unnecessary to use Raycast in your case, since you have the reference of the sepcific target.

if(Vector3.Angle(rayDirection, transform.forward) < fieldOfViewRange && Vector3.Distance(transform.positon, player.position) < alertRange)

will just be fine. Anyway, if you insist on using raycast you can write like this

if (Physics.Raycast (transform.position, rayDirection, out hit, alertRange))

Check ‘Handles.DrawSolidArc’ in Unity Documents and follow it’s example code if you want to debug advanced visual info.