I have 16 levels in my scene but how to save which level is completed.
I have a level selection menu and dont want the player to start the level he hasnt completed before. What is the best way to do this?
You can save data in files (go check Serialization)
Or just use Unity - Scripting API: Object.DontDestroyOnLoad
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
void Awake() {
DontDestroyOnLoad(transform.gameObject);
}
}
I had seen the tutorial but i dont get the idea how to use it in this situation.
A way to do this is to set a Boolean for each level. i.e. level1 = true (as you want to be able to play the first level from startup) then level2 = false (until level1 = true) etc. So for each level set the next level boolean to true (and make all true levels clickable).
Another way is to set an integer value (levelGotTo or something) and read that integer value everytime you load your level selection. (If levelGotTo >0 AND levelGotTo <3 THEN levels 1 AND levels 2 ARE clickable)
You will definitely want to use [PlayerPrefs][1] in order to save which level the user has got to for the next time they play the game.
Hope you find this useful.
[1]: Unity - Scripting API: PlayerPrefs.SetInt