create an array of loaded scenes

I am loading scenes into my main scene and I want to be able to control the visibility. What type would I make an array of and how would I do that? I tried creating an array of gameobjects, but I got a lot of conversion errors. Thanks.

        for(int i = 0; i < levels.Length; i++)
        {
            Application.LoadLevelAdditive (levels[i]);
            Debug.Log (levels[i]);               
        }

You need to give LoadLevelAdditive an index or a name, so if you’d want to load a bunch of levels, you need to put their names or indices in an array or list. So you have to make it an array of int or string.

I made a room system before. Every level had a parent object that could be activated/deactivated, or easily destroyed.

The parent object had the same name as the level so I could just look for the game object with that name and do whatever I wanted with it.

Yea, that’s what I was trying to do but I was stuck on the array/list part. Can you give me an example? Thanks.

You’ll have to do that manually as far as I know. That’s what I did. I manually and deliberately gave all objects in each level a parent and named it after it’s level. Then I manually had to give that name to the script that was responsible for loading that level.

You could do something like this:

//manually configure in inspector
public string[] levelNames;

private GameObject[] levelParents;

void Start()
{
    levelParents = new GameObject[levelNames.Length];

    for(int i = 0; i<levelNames.Length; i++)
    {
        Application.LoadLevelAdditive(levelNames[i]);
        levelParents[i]=GameObject.Find(levelNames[i]);
    }
}

I haven’t tested this, but this should make an array of GameObjects, which are the parents of each level.

You’ll have to put all objects in each level under a parent GameObject and give it the same name as the level it’s in, like in my picture. Then you could fill out their names in levelNames in the inspector.

It would be easier if levels had their own type and could be dragged and dropped around like most other assets.