How can I have hundreds of level in my game without make my game size huge?

I have an idea to create a futuristic top down shooter that is going to have like 100 levels.

I’m wondering how to do this without having 100 scenes in my game because that would be inefficient. I’ve searched a bit on this topic and find out you can make levels using text files. Can someone explain more deeply into this because this kinda confuses me.

Thanks!

Here are two solutions that come to mind:

1) Tiles
If you can split your levels in tiles that all have the same dimension, then you could represent your level by an array [width, height] of those tiles.
A tile can represent a floor, a wall, an empty space, whatever. You have one prefab defined in Unity for each of those tiles, allowing you to simply store the structure of your levels in a flat file.
The file structure would be an two-dimensional array of values, each value associated with a prefab. Example: 0 = Nothing, 1 = Floor, etc …

Example:
1 0 2 3 0 0 0
0 1 1 1 0 2 3
0 0 0 2 0 0 0

Then, when you load your level, you simply read the file and instantiate the tile at the position indicated.

2) No Tiles
If you do not want to use tiles, there is another possibility. Each of your levels are defined by a list of prefabs positioned at a certain position, with a certain rotation, and a certain scale. Then, you only need to store in your flat file a list of prefab names, with their position, rotation and scale.
You could write this using your own format, or use XML or JSON, which are useful languages for serializing information.
Writing your own format could look like that:

“Planet1”, (10, 7, -2), (90, 0 ,0), (1, 1, 1)
“Enemy2”, (5, 5, 9), (0, 0, 0), (1, 1, 1)
“Enemy2”, (10, 7, 9), (0, 0, 0), (1, 1, 1)

The first value is the name of the prefab, the second is the position, then comes the rotation and the scale.
When loading a level, your game will read the file and instantiate the prefabs at the correct position.

I hope that helps.

I don’t think that’s what the OP is asking.

I wouldn’t worry about having a lot of scenes, although it does greatly depend on the type of game you’re making. One technique for level based games is to have an initial scene load that has all your controller/manager scripts. From there you can use SceneManager to load scenes using the SceneLoadMode.Additive. When you’re done with those objects just unload the scene and load a new one.

The “inefficiencies” really just come from duplicate data. So, Cameras, gamemanagers, backgrounds, etc. No sense in having all those in every single scene if it’s the kind of game that re-uses assets. Just save scenes with objects specific to that scene.

Angry birds, for example, could use this technique, where the UI and backdrop and all that are a scene, but the pigs and blocks are a separate scene that are loaded on top of the original scene.

A

Actually, Sheikz’s answer was the one I’m looking for but thanks for the info!

That helped but I have a couple more questions to ask…
My game would be a non-tile game so I’m wondering which format is better? XML, JSON or YAML? By the way, it’s going to be a web game with an android and possibly iOS version.