O'Reilly logo

Unity 5.x Game Development Blueprints by John P. Doran

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

Spawning obstacles at runtime

Now that we have a simple obstacle, we can now spawn a number of them through code using this object as a reference. To make this easier, let's make the obstacle a prefab:

  1. Go to the Project tab and open up the Prefabs folder. Then, from the Hierarchy tab, drag and drop the Obstacle object into the Project tab's Prefabs folder. The obstacle object should turn the object.
  2. Once this is done, select the Obstacle objects from the Hierarchy tab and delete it because we won't need it anymore.
  3. Now that we have the obstacles, let's start spawning them. To do this, open up the GameController script and add the following variables:
     [Header("Obstacle Information")] [Tooltip("The obstacle that we will spawn")] public GameObject obstacleReference; ...

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