MainMenuScript.cs 933 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using UnityEngine.UI;
  4. using System.IO;
  5. public class MainMenu : MonoBehaviour
  6. {
  7. public Button continueButton; // Link this in the inspector
  8. public string gameSceneName = "Valley";
  9. // Static variable persists between scene loads
  10. public static bool shouldLoadSave = false;
  11. void Start()
  12. {
  13. // Disable the Continue button if no save file exists
  14. string path = Application.persistentDataPath + "/savegame.json";
  15. if (continueButton != null)
  16. {
  17. continueButton.interactable = File.Exists(path);
  18. }
  19. }
  20. public void NewGame()
  21. {
  22. shouldLoadSave = false;
  23. SceneManager.LoadScene(gameSceneName);
  24. }
  25. public void ContinueGame()
  26. {
  27. shouldLoadSave = true;
  28. SceneManager.LoadScene(gameSceneName);
  29. }
  30. public void QuitGame()
  31. {
  32. Application.Quit();
  33. }
  34. }