Choosing destinations – finding a random spawn point
Many games make use of spawn points and waypoints. This recipe demonstrates choosing a random spawn point, and then the instantiation of an object at that chosen 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 a random spawn point, follow these steps:
- In the
Scene
panel, create a sphere (by navigating toCreate | 3D Object | Sphere
) sized as(1, 1, 1)
at(2, 2, 2)
position, and apply them_red
Material. - In the
Project
panel, create a new Prefab (by going toCreate | Prefab
) namedPrefab-ball
, and drag your sphere into it (and then delete the sphere from theHierarchy
panel). - In the
Scene
panel, create a new capsule (by navigating toCreate | 3D Object | Capsule
) namedCapsule-spawnPoint
at (3, 0.5, 3
), and give it a tag ofRespawn
(this is one of the default tags that Unity provides):
Note
For testing, we'll leave these...