Browse Source

Merge pull request #661 from MeMark2/save-menu-fix

Account for SaveMenu DontDestroyOnLoad problems
master
Chris Gregan 7 years ago committed by GitHub
parent
commit
3299b029f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      Assets/Fungus/Scripts/Components/SaveMenu.cs

15
Assets/Fungus/Scripts/Components/SaveMenu.cs

@ -58,6 +58,8 @@ namespace Fungus
protected static SaveMenu instance; protected static SaveMenu instance;
protected static bool hasLoadedOnStart = false;
protected virtual void Awake() protected virtual void Awake()
{ {
// Only one instance of SaveMenu may exist // Only one instance of SaveMenu may exist
@ -69,7 +71,14 @@ namespace Fungus
instance = this; instance = this;
GameObject.DontDestroyOnLoad(this); if (transform.parent == null)
{
GameObject.DontDestroyOnLoad(this);
}
else
{
Debug.LogError("Save Menu cannot be preserved across scene loads if it is a child of another GameObject.");
}
clickAudioSource = GetComponent<AudioSource>(); clickAudioSource = GetComponent<AudioSource>();
} }
@ -89,8 +98,10 @@ namespace Fungus
saveManager.StartScene = SceneManager.GetActiveScene().name; saveManager.StartScene = SceneManager.GetActiveScene().name;
} }
if (loadOnStart) if (loadOnStart && !hasLoadedOnStart)
{ {
hasLoadedOnStart = true;
if (saveManager.SaveDataExists(saveDataKey)) if (saveManager.SaveDataExists(saveDataKey))
{ {
saveManager.Load(saveDataKey); saveManager.Load(saveDataKey);

Loading…
Cancel
Save