Day 10: Spawning Objects in Unity without the Clutter

The goal is to create a system that instantiates new objects during the game in addition to those present at the beginning of the game.
To do this you need to create a script. The SpawnManager.

Let’s start
First, we need to create an empty object and its script.

Inside the script, we have to create the variables of the game objects that we want to instantiate.

Now we need to define the logic by which our objects will be instantiated. That is the position and time of when they are to appear.

We define our coroutine:

finally, we start the coroutine in the Start() method:

We save and return to Unity, now in our Inspector we can drag our prefabs and try if everything works correctly.

This should be the result.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store