How to organize an Infinite runner level blocks

Hi there!

I’m working on an Infinite Runner game.
I have created many level blocks(sections) with different obstacles and pick-ups for the player. They are positioned and placed manually, in such a way, to give the player a challenge. I thought that making every block a prefab and placing every obstacle and coin as a child of that prefab is going to be easier for me…because the player is going to run and these block prefabs are going to be randomly spawned in front of him and then destroyed after the player gets past them.
It worked well.

Then I wanted to make a change on my coins. So naturally I took the coin prefab, made the changes, and applied them hoping that the change is going to take effect on all my blocks… Well…it didn’t.
Then I found out that nested prefabs don’t work in Unity, so now I have to reorganize everything again?

How do I create organized level blocks, and then make them randomly spawn in front of the player? Is there any other option besides prefabs? Don’t tell me I have to use a script for every block?

Think about Banana Kong, Temple Run, Subway Surfers. The levels seem random, but it’s an organized randomness with certain portions of the level repeating themselves. That’s what I’m trying to do, and I don’t know how to organize it…

Thank you very much. I hope you guys can help me.

Instead of putting the coins/pickups directly onto the prefabs, you can instead have empty game objects there as markers. When the section is spawned, you then spawn in the items at those locations.

This also gives you the ability to adjust how many coins or pickups are spawned on the fly. This way one section can have none/few/many coins/pickups without needing different prefabs for them. For instance, if you had just given the player a speed pickup, then spawn in a section with a marker for a pickup, you can decide if you want to give another so soon, give a different pickup, or skip it.

The best way (IMO) to do this is to have a simple script on each section that holds arrays with all markers in them (one for coins, one for pickups, etc). The spawner script can then use this to easily access the marker locations without needing to use GameObject.Find or whatever.

Also, it might be a good idea to look into object pooling since you’re doing a lot of creation/destruction of objects. Instead of creating each section/coin/pickup and destroying them once past, you create a pool of each (guessing how many you may need max at any one time and adding a little buffer on top) and set them inactive. When needed you take one and position it then set it active.

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling