Rather than just choosing a random spawn point or waypoint, sometimes, we want to select the one closest to some object (such as the player's GameObject). In this recipe, we will modify the previous one to find the nearest spawn point to the player's cube, and use that location to spawn a new red ball prefab.
Choosing destinations – finding the nearest spawn point
Getting ready
This recipe builds upon the previous recipe. So, make a copy of this project, open it, and then follow the steps in the next section.
How to do it...
To find the nearest spawn point...