how to make the user return to the level where he left off the last time after exiting and returning to the game. Help Please!
You need to save it somewhere. Either in JSON, XML, or using PlayerPrefs (Not really recommended but okay for small games).
For example add a “Save button”, when the player presses it set
PlayerPrefs.SetInt("CurrentLevel", SceneManager.GetSceneByBuildIndex(SceneManager.Scene.buildIndex);
This will save the current build index to a player pref called “CurrentLevel”.
Then on your main menu have a load button, when you press it you do
int level = PlayerPrefs.GetInt("CurrentLevel");
Scenemanager.Loadscene(Scenemanager.GetSceneByIndex(level));
(This is psuedocode idr all these off the top of my head)
For implementing JSON or XML there’s many tutorials on youtube.
SAVE & LOAD SYSTEM in Unity - YouTube - and then just save the variable to your level (as a String or an int, depends on your preference) as show in this video.
Then create a loading screen as followed: How to make a LOADING BAR in Unity - YouTube. Name the scene “Starter” or so.
Set the “Starter” scene as the start scene (Build settings → set “Starter” as scene 0).
Combine both scripts so you get something like that:
private void Start()
{
if (SceneManager.GetActiveScene().name == "Starter")
{
PlayerData data = SaveSystem.LoadPlayer();
if (data != null)
{
Player.level = data.player_level;
Player.health = data.player_health;
}
if (Player.level == 1)
{
StartCoroutine(Load(1));
}else
{
StartCoroutine(Load(6));
}
In the If-statment you just check if the e.g. menu should be loaded or the level.