Loading and Saving

Trying to implement a basic saving system into my ball rolling game. Basically the functionality I am trying to achieve is it auto saves while you’re playing, and on the menu, there is a Load button.
This is my saving class, attached to a game object
using UnityEngine;
using System.Collections;

public class saving : MonoBehaviour {

	public static int currentLevel;

	void Awake()
	{
		DontDestroyOnLoad (transform.gameObject);
		currentLevel = PlayerPrefs.GetInt("LastLevelLoaded");
	}

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		if(Application.loadedLevel != currentLevel)
		{
			currentLevel = Application.loadedLevel;
			PlayerPrefs.SetInt("LastLevelLoaded",currentLevel);
		}
	}
}

And this is a loader, attached to a game object as well
using UnityEngine;
using System.Collections;

public class Load : MonoBehaviour {

	void Awake()
	{
		DontDestroyOnLoad (transform.gameObject);
	}
	
	public void Loaders()
	{
		Application.LoadLevel (saving.currentLevel);
		// Call the LevelManager and set the last level.

	}
	

		

}

When I initially press load on the menu, it reloads my “loading” scene, and when I go to play the main level, and then I click menu, and attempt to load it, it does nothing. It loads the menu again I believe.

I think you could just exclude your Menu(s) or scenes you don’t want the script to save by adding

(Application.loadedLevel != (index of the menu you want to exclude))

to your if statement in the Update() of saving.
This way, if the scene you loaded is included in the if statement, it won’t be saved. You could also use

(Application.loadedLevelName != “MENUNAME” ))

to refer to your scenes by their names if that is easier.
There might be better, more elegant solutions to this problem, but I believe this should work.
Cheers.

W.B.

I solved this by just using a level unlock system: Loading...