ENEMEY AI FOLLOW

hi guys i have a code that when i start the game the enemy already starts to follow the player, but i’m trying to make the enemy of my game to follow the player when it identify him at a certain range, but i dont have a clue how to start can someone help me?

You could get a simple cone 3d asset attach it to the enemy (cone of view) and
attach somethig like this to it:

    RaycastHit hitInfo;
    void OnTriggerEnter(Collider collider)
    {
        if (collider.tag = "Player")
        {
            if (Physics.Raycast(transform.position, (collider.transform.position+Vector3.up)));
            {
                // follow and or attack
            }
        }
    }