title: How to get the closest object in the navMesh and making the agent move towards it
body: <p>At the moment I have a semi-dynamic layout where my agent follows the randomized waypoints and after he reaches one, he deletes said waypoint.
  However, I want him to scan the closest waypoint to the object. Taking into account vector3.distance goes over obstacles, what are the other solutions.</p>
  
  <pre><code>    public NavMeshAgent agent;
      public GameObject[] waypoints // Waypoints
      public Transform[] locations // Waypoint location
      for (int x = 0; x &lt; waypoints.Length; x++) // Sets random position
      {
          if (x &lt; 5) 
          {
              waypoints[x].transform.position = new Vector3(Random.Range(-33.0f, 30.0f), 3.575465f, Random.Range(30.0f, -35.0f));
          }
  
          for (int z = 0; z &lt; waypoints.Length; z++)
          {
              if (z &lt; 5 &amp;&amp; waypoints[z] != null)
              {
                  agent.SetDestination(locations[z].position);
              }
          }
      }
  </code></pre>