How to detect if NavAgent has reached hit.point? (2) Distance doesn't work?

Here’s the new code:

float dist; 
RaycastHit hit;

void Update()
{
    if (Input.GetMouseButtonDown(1))
    {
        float dist = Vector3.Distance(agent.transform.position, hit.point);

        if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
        {
            agent.SetDestination(hit.point);

            if (dist < .1f)
            {
                print("Destination reached");
            }
        }
    }

And it doesn’t work. The distance isn’t really registered. The message “Destination reached” appears the second I click which is not what I want. The actual distance doesn’t seem to matter at all. I want the message to only appear AFTER the agent has reached the hit.point.

You put if inside another if, this in your code makes the message appear only when you click the right mouse button. Try this:

float dist; 
RaycastHit hit;

void Update()
 {
if (Input.GetMouseButtonDown(1))
 {
    float dist = Vector3.Distance(agent.transform.position, hit.point);
 }

if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit, Mathf.Infinity))
 {
    agent.SetDestination(hit.point);
 }

if (dist < .1f)
         {
             print("Destination reached");
         }
 }