O'Reilly logo

Unity 5.x Cookbook by Chico Queiroz, Matt Smith

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Choosing destinations – find the nearest (or a random) spawn point

Many games make use of spawn points and waypoints. This recipe demonstrates two very common examples of spawning—the choosing of either a random spawn point, or the nearest one to an object of interest (such as the Player's character), 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 next steps.

How to do it...

To find a random spawn point, follow these steps:

  1. Create a Sphere sized as (1,1,1) at (2,2,2) position, and apply the m_red Material.
  2. Create a new Prefab named Prefab-ball, and drag your Sphere into it (and then delete the Sphere from the Hierarchy ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required