Creating Basic Template For Future Levels

Please see the attached image.

The goal is for the player to make it to the other side without getting hit by an explosion (represented by a red block). Each obstacle contains a total of 49 red cube objects that will rotate on and off every X seconds.

My goal is to simplify developing future levels. I’m trying to build an Obstacle Manager to make it easier to edit these explosion patterns from the inspector level. Basically, I want the Obstacle Manager script applied to a parent object called Obstacle which will have 49 child objects (red blocks) that can have the start explosion time and repeat explosion time set from the Obstacle inspector.

My code below works for a single cube. I drag the cube game object under the inspector and set the start time and repeat time, but how can I adjust my code to accomodate 48 additional objects?

public class ObstacleManager : MonoBehaviour
{
    [SerializeField] GameObject cube;
    [SerializeField] private float startTime = 1f;
    [SerializeField] private float repeat = 1f;

    private bool active = false;

    // Start is called before the first frame update
    void Start()
    {
        InvokeRepeating("StartExplosions", startTime, repeat);
    }

    void StartExplosions()
    {
        if (!active)
        {
            cube.SetActive(true);
            active = true;
        }
        else if (active)
        {
            cube.SetActive(false);
            active = false;
        }
     
    }
}

Surely there is an easier way to go about it than

[SerializeField] GameObject cube1;
[SerializeField] private float startTime1 = 1f;
[SerializeField] private float repeat1 = 1f;

[SerializeField] GameObject cube2;
[SerializeField] private float startTime2 = 1f;
[SerializeField] private float repeat2 = 1f;
.
.
.
[SerializeField] GameObject cube49;
[SerializeField] private float startTime49 = 6f;
[SerializeField] private float repeat49 = 1f;
  1. You can use text files for each level and make a LevelManager who’s reading those files and spawning the objects.
  2. You can make Empty objects with names “LevelXX”. At the start of the game only Level01 is enabled. In this Empty object just add your red boxes.
  3. Make a new scene for each level.

I prefer option 1, more elegant in my opinion. But if i’m time pressed i’ll be using option 2.
The 3rd option is here only to have 3 options :slight_smile: Don’t use the 3rd!