- Home /
Open a new level when you finished the current level
Hi all, I have a problem..
I have made a game with 30 levels, now you can just load every scene and play it via a scene with alot of buttons that open the levels, but that is not what I want. I want to make it so that you first finish for example level 1, and than you can play level 2. And also a thing that is important, that when you leave the game and you launch the game later, that you not playing all the levels again, that you can play for example level 5, if you was there.
I program with c#
I hope it's clean, but my english is not the best :(
(Btw, i'm not a pro with unity of c#, i use unity now for 5 months. So i hope you guys can help my.)
Answer by Landern · Jun 26, 2015 at 02:10 PM
First off this isn't a service, you will have to do the leg work here. So have some things to look into...
You can save whatever settings you want by using the PlayerPrefs, you can store and (Save) values to persist through out the execution of your game.
For levels, you might start with ensuring that you're using some naming convention so you can use just one script to load a level.
Lets say you're level naming scheme is something like this: "level_##.scene" and that is what you load into the build settings.
that would leave you having a list like:
Level_1.scene
Level_2.scene
Level_3.scene
...
Level_10.scene
You can then use the combination of the current level and a script with custom methods that build out the next seen to load:
public void LoadNextLevel(int levelIndex)
{
// string.Format takes the params after the string
Application.LoadLevel("Level_" + levelIndex.ToString());
}
What you do to call the LoadNextLevel method is up to you as well as the placement.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to execute a Skript global? 2 Answers
Multiple Instances of My Current Scene? 0 Answers