You have to request the agent to move to the valid navmesh position that's closest to the requested destination.
- The path result may not available until after a few frames. Use pathPending to query for outstanding results.
- If it's not feasible to find a valid nearby navmesh position (e.g. Scene has no navmesh) no path is requested. Use SetDestination and check the return value if you need to handle this case explicitly.
You can refer to the following link for more information regarding the NavMeshAgent:
https://docs.unity3d.com/ScriptReference/AI.NavMeshAgent.html
You can also check if a world position (such as your random scatter point) is on the NavMesh with a check like so:
NavMesh.Raycast(point, point, out navHit)
This attempts to sketch a raycast from position 'point' to itself, returning false if no NavMesh is generated, the point is below the mesh or too far above it.
Then you can find the closest edge to this point with the following:
NavMesh.FindClosestEdge(point, out navHit)
If true - the closest edge is found, the valid waypoint position will be stored in navHit.position.
If you are looking to learn more about Artificial Intelligence then you visit Artificial Intelligence Tutorial and Artificial Intelligence Course. Also, if you are appearing for job profiles of AI Engineer or AI Expert then you can prepare for the interviews on Artificial Intelligence Interview Questions.