Question: My code can pause in the game but I need to save and load the game as well and the last part of the coding

My code can pause in the game but I need to save and load the game as well and the last part of the coding is not working:

using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement;

public class Pause : MonoBehaviour { public static bool GameisPaused = false;

public GameObject pauseMenuUI; // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { if (GameisPaused) { ResumeGame(); } else { PauseGame(); } } } public void ResumeGame() { pauseMenuUI.SetActive(false); Time.timeScale = 1f; GameisPaused = false; }

void PauseGame() { pauseMenuUI.SetActive(true); Time.timeScale = 0f; GameisPaused = true; }

public void LoadMenu() { Time.timeScale = 1f; SceneManager.LoadScene("Menu"); }

public void Save() { PlayerPrefs.SetInt("currentscenesave", SceneManager.LoadScene); }

public void Load() { SceneManager.LoadScene(PlayerPrefs.GetInt("currentscenesave")); }

public void QuitGame() { SceneManager.LoadScene("Credits");

} }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!