Get GameObjects Namy By Camera Range

Hello Everyone

i write a script that show the player name that i’m aiming
and its works fine.

but i want him show who is in The Range of my camera not who i’m aiming

I Use This Code :

    	 RaycastHit hit;
    	if(Physics.Raycast(transform.position + new Vector3(0,0.6f,-1.6f),transform.TransformDirection(Vector3.forward),out hit)){	
			
    	name = hit.collider.transform.parent.gameObject.name;
    	teamtag = hit.collider.transform.tag;

    				}

I Think Its Something Close To This :

if (Physics.Raycast(myCamera.ScreenPointToRay(Input.mousePosition), out hit)){

Try adding a Collider Component to your Camera object, suitably positioned and adjusted to represent the range you are interested in. You can then check if the players are within the range with OnCollisionEnter() / OnCollisionExit() or OnTriggerEnter() / OnTriggerExit() (if you set the Collider to be IsTrigger), and then use the Collision / Collider information these methods provide to get the player objects’ names, calculate further range distances, display an “in-range” indicator, etc.

An example (assuming a Collider set to IsTrigger):

using UnityEngine;

public class RangeIndicationScript : MonoBehaviour
{
    Transform collidedObj;
    float distance;

    void Update()
    {
        distance = !collidedObj ? 0.0f : Vector3.Distance(transform.position, collidedObj.transform.position);
    }

    void OnGUI()
    {
        Rect lblpos = new Rect(10, 10, 200, 50);
        string lbl = !collidedObj ? "No object in range." : System.String.Format("{0} is in range!

Distance: {1}", collidedObj.name, distance);
GUI.Label(lblpos, lbl);
}

    void OnTriggerEnter(Collider col)
    {
        collidedObj = col.gameObject.transform;
    }

    void OnTriggerExit(Collider col)
    {
        collidedObj = null;
    }
}