- Home /
Single scene, multiple levels
Hi,
I have many levels defined in yaml files. It is a simple board game so the level files define the format of the board, tile types and positions for the game elements. I made it this way so that it would be very easy to design new levels -- just save a new yaml file and voil.
Now to load a level, I need to add the same scene multiple times and load the level file based on the scene index (nothing really changes in the scene, the level data is all in the yaml file). This is a little inconvenient for two reasons: I have to manually add the same scenes to the game build and to track the correct indexes.
I wish I could avoid having to add the scene multiple times, but I'm afraid there is nothing I can do. Is there a different strategy for this?
I hope the question was clear. :)
Answer by StephanK · Nov 07, 2010 at 01:50 PM
I guess you already have a function that initializes your game when you start a scene. Just modify this function so it takes the level index as parameter and then initialize using the specific data from you yaml files. All you have to do now is reset the game state when a level ends (removing objects, reset points etc.), then call you init function and you're done. No need for multiple scenes.
Thanks for your answer. I'm a little confused with this. Yes, I have a script that loads a level following the definition in yaml. So I understand that I'll have to manage all the object destruction, as you say, and basically load a scene once and from that manage it all myself to change to different level.
And if you don't have an easy way to reset everything, just reload the level (Application.LoadLevel(0)), presumably after setting some object that knows about the next yaml file to be DontDestroyOnLoad.