Simple - Save and Loading Scene
Hello, I'm new to scripting and this is a simple scene save script. Its really simple. All I want it to do is save when I press one button, and load when I press another (I to save, O to load). What it is supposed to do is get the current scene and save it so that when you press load it will take you to that scene. Well this code simple does not work. Ive tried several ways of doing it but no success. It doesn't have any errors or anything, it just refuses to do what I want it to do. Here's the code
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;
public class SaveLoadGame : MonoBehaviour {
void Save () {
if (Input.GetButtonDown ("i"))
SaveGame ();
}
void Load () {
if (Input.GetButtonDown ("o"))
LoadGame ();
}
public void SaveGame () {
PlayerPrefs.SetInt ("Level", SceneManager.GetActiveScene ().buildIndex);
print ("Game saved");
}
public void LoadGame () {
SceneManager.LoadScene (PlayerPrefs.GetInt ("Level"));
print ("Game loaded!");
}
}
Thanks for any info!
Comment