Move to Object "then" do action

Hi.
been racking my brain on how to do this but not sure. if anyone can point me in the correct direction would be great.

Basically when i select a “unit” then click a “resource” i want the unit first to move to the resource THEN start doing an action (ie: gathering)

but the code ive came up with so far starts the gathering way to early. ive tried doing an if transform.position == transform.position of the hit object but it never runs as at the point of clicking it will not be at the position needed (still needs to move first)

 public void Gather()
    {
        StartCoroutine(GatherAction(gatherTime));
    }

     IEnumerator GatherAction(float waitTime)
    {

        RaycastHit hit;
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit))
        {
            navAgent.SetDestination(hit.transform.position);

                Debug.Log("Starting to Gather");
                yield return new WaitForSeconds(waitTime);
                Debug.Log("Gathering Complete");
            
        }
    }

Try setting a variable to ‘isReadyToGather’, use that as the trigger for gathering action. That way it only is ready to gather if it has entered a certain radius of the destination.

This can go in the update function, so gather only runs if the variable is true.

Here’s my solution, I’m sure there are more elegant ways but this works for me:

In update, run a method that checks to see if the unit is close enough to do the action. For my script this means the targetPos & currentPos I set up in the movement part of the script are equal. You could also add an offset to this if you want them to just be within a certain radius of each other before the gathering is possible.

void Update()
    {
        IsNearEnoughChecker();
    }

void IsNearEnoughChecker()
     {
         if (currentPos == targetPos)
         {
             isNearEnough = true;
         }
         else if (currentPos != targetPos)
         {
             isNearEnough = false;
         }
     }

Then I have this Gather function hooked up to a button on the GO to be interacted with (i.e. plant to harvest)

    public void Gather()
    {
        SetTarget();
        DoMovement();
        StartCoroutine(GatheringCR());
    }

public void SetTarget() {
      targetPos = new Vector3(transform.position.x - positionOffset.x, transform.position.y, transform.position.z); 
      //here I added an offset because I don't want the unit to end up right on top of the GO to be interacted with
}
   
public void DoMovement()
    {
        currentPos = transform.position; 
        startPos = transform.position; 
        //for regular movement, targetPos is set in another script that deals with selection. For specifically moving to the GO to be interacted with, the target is set in the method above

        if (currentPos != targetPos) 
        {
            transform.position = Vector3.MoveTowards(transform.position, targetPos, speed * Time.deltaTime); 
        }
    }

IEnumerator GatheringCR ()
    {
        while (isNearEnough == false)
        {
            yield return new WaitForSeconds(1); 
           //there definitely exists a better solution than WaitForSeconds here, but I'm just learning coroutines... if you don't mind an extra wait time up to one second it works great
        }

        while (resourcesLeft > 0f)
        {
            resourcesLeft = resourcesLeft - 1;
            resourcesGiven = startingResources - resourcesLeft; 
            //I use both of those variables because I want to be able to harvest only part of the resources and come back later; this way there is a linked counter on both the unit and the plant for how many resources have been transferred

            yield return new WaitForSeconds(1);
        }
        
    }