转自: http://wiki.ceeger.com/script/unityengine/classes/navmesh/navmesh.sampleposition
转自: http://answers.unity3d.com/questions/475066/how-to-get-a-random-point-on-navmesh.html
I generated a random point with in a unit sphere and multiplied it by the max distance I wanted my agents to walk:
Vector3 randomDirection = Random.insideUnitSphere * walkRadius;
I then added my agents current position to this vector and used the NavMesh.SamplePosition function to find the close position on the NavMesh:
randomDirection += transform.position;
NavMeshHit hit;
NavMesh.SamplePosition(randomDirection, out hit, walkRadius, 1);
Vector3 finalPosition = hit.position;
I then used final postion as the destination for my agent.
Hope this helps!