SOLVED
You could do a simple version using PlayerPrefs.
On scene load set current level using SetInt.
Your load level function just calls GetInt and loads that level index.
All the examples are in karls post, just read them and play around with it. It is really simple ![]()
Start at the beginning: Learn
Here is an extremely simple script.
Instead of using the build index number, it saves the name of the scene to the PlayerPrefs and loads it back in and loads the scene with that name.
using UnityEngine.SceneManagement;
void Save()
{
Scene openScene = SceneManager.GetActiveScene();
PlayerPrefs.SetString("Saved Level", scene.name);
}
void Load()
{
string sceneToLoad = PlayerPrefs.GetString("Saved Level");
SceneManager.LoadScene(sceneToLoad);
}
I agree with the other guys, start from the very beginning but everyone learns differently, if the online videos dont help maybe try to get a book?
What are the errors.
I wrote that without Unity.
EDIT:
I remebered that it is not a full script
I picked the specific parts that you need.
The using statement at the top should be placed at the top of a script and the functions placed within the class.
It is missing things to be a full script on its own and I wrote it that way specifically
Just let me know if you need me to fill in the blanks.
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Saver : MonoBehaviour
{
void Save()
{
string openScene = SceneManager.GetActiveScene().name;
PlayerPrefs.SetString("Saved Level", openScene);
}
void Load()
{
string sceneToLoad = PlayerPrefs.GetString("Saved Level");
SceneManager.LoadScene(sceneToLoad);
}
}
Just opened Unity to fix it.
It simply did not like me getting the name while saving so I got the string beforehand.
It compiles now but obviously I need your confirmation if it works.
Dont forget to call Save(); and Load();
I will write a couple of steps here.
What you have so far is good.
- Create an empty GameObject and attach the Saver script to it.
- Drag that GameObject onto the public fields on the Loader and Save scripts.
haha anytime.