- Home /
Set Level inquiry/data from the inspector
I am planning of a puzzle game, where lets say there are 50 leves (just like IQ games) but I want to have a single Scene for all 50 levels and of course designing 50 scenes is not the way.
since all levels are almost similar and vary only in some data, I want to write a class named "Level" and in the main controller script have an array of Levels where I can specify all the Level details just from the inspector.
I don't know how this is possible since the built in array is visible in the inspector, while most of other collections don't.
Mainly I need to have an array of custom class, where the class and its public variables appear in the inpector.
I have created a tree in the inspector of how I want it to be(of course its been modified in photoshop), check the picture and any other solution would really help.
Answer by Bunny83 · Jun 10, 2013 at 03:05 PM
Just create a class like this:
[System.Serializable]
public class Level
{
public string name;
public int[] columns;
public Camera secondaryCamera;
}
Note: If the first variable in the class is a string, the inspector will show this string instead of the "Element 0" thing.
Just as a little warning: If your Level class is truly the same for all levels this should work pretty well but watch out, if you change something in the Level class it might break all the already setup data.
50 is quite a bit, you might just want to use MonoBehaviour components instead:
public class Level : MonoBehaviour
{
public string name;
public int[] columns;
public Camera secondaryCamera;
}
And attach one for each level. You can attach all to the same GameObject or add them to empty GameObjects. One script per GO is usually the safest way. This way you could even save them as individual prefabs