Rather than just choosing a random spawn point or waypoint, sometimes, we want to select the one that's closest to an object (such as the player's GameObject). In this recipe, we will modify the previous recipe to find the nearest spawn point to the player's cube, and then use that location to spawn a new red ball prefab:
Figure 9.11 – Spawning a sphere at the spawn point capsule that is nearest the player cube