Im trying to load my most recent saved data from the main menu scene. From the main menu scene when i press LOAD it should load the game with the most recent preferences . Currently the save and load is working but only within the Game scene not the Main menu Scene. This is the code below. In the main menu all i’m using is a Scene Manager to load the game.How exactly can i load a game with the loaded data already in place?
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SaveandLoad : MonoBehaviour {
public GameObject BackgroundMusic;
public GameObject SFX;
public GameObject LightIntensity;
public GameObject muteButton;
public Toggle [] resolutionToggles;
public Toggle fullScreen;
bool muted;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
public void Save(){
float mastervolume= BackgroundMusic.GetComponent<Slider>().value;
float SFXvolume=SFX.GetComponent<Slider>().value;
float Lightintenvalue= LightIntensity.GetComponent<Slider>().value;
PlayerPrefs.SetFloat("BackgroundMusic",mastervolume);
PlayerPrefs.SetFloat("SFXvolume",SFXvolume);
PlayerPrefs.SetFloat("LightInten",Lightintenvalue);
if(resolutionToggles[0].isOn ==true){
PlayerPrefs.SetInt("Resolution01",1);
}
else if (resolutionToggles[0].isOn ==false){
PlayerPrefs.SetInt("Resolution01",0);
}
if(resolutionToggles[1].isOn==true){
PlayerPrefs.SetInt("Resolution02",1);
}
else if (resolutionToggles[1].isOn ==false){
PlayerPrefs.SetInt("Resolution02",0);
}
if(resolutionToggles[2].isOn==true){
PlayerPrefs.SetInt("Resolution03",1);
}
else if (resolutionToggles[2].isOn ==false){
PlayerPrefs.SetInt("Resolution03",0);
}
if(fullScreen.isOn==true){
PlayerPrefs.SetInt("FullScreen",1);
}
else if (fullScreen.isOn ==false){
PlayerPrefs.SetInt("FullScreen",0);
}
if(muted==true)
{
PlayerPrefs.SetInt("Muted",1);
}
if(muted==false)
{
PlayerPrefs.SetInt("UnMuted",0);
}
}
void Awake(){
DontDestroyOnLoad(this);
}
public void Load(){
//Debug.Log(PlayerPrefs.GetFloat("BackgroundMusic"));
BackgroundMusic.GetComponent<Slider>().value=PlayerPrefs.GetFloat("BackgroundMusic");
SFX.GetComponent<Slider>().value=PlayerPrefs.GetFloat("SFXvolume");
LightIntensity.GetComponent<Slider>().value=PlayerPrefs.GetFloat("LightInten");
//Debug.Log(PlayerPrefs.GetInt("Resolution01"));
//Debug.Log(PlayerPrefs.GetInt("Resolution02"));
//Debug.Log(PlayerPrefs.GetInt("Resolution03"));
if(PlayerPrefs.GetInt("Resolution01")==1){
//Debug.Log("Resolution01");
resolutionToggles [0].isOn=true;
}
if(PlayerPrefs.GetInt("Resolution02")==1){
//Debug.Log("Resolution02");
resolutionToggles [1].isOn=true;
}
if(PlayerPrefs.GetInt("Resolution03")==1){
//Debug.Log("Resolution03");
resolutionToggles [2].isOn=true;
}
if(PlayerPrefs.GetInt("FullScreen")==1){
//Debug.Log("FullScreen");
fullScreen.isOn=true;
}
if(PlayerPrefs.GetInt("Muted")==1)
{
AudioListener.volume=1;
}
if(PlayerPrefs.GetInt("Muted")==0)
{
AudioListener.volume=0;
}
}
public void ClickedButton()
{
muted= !muted;
//Debug.Log(AudioListener.volume);
}
}