can anywone help me with my code? i try using chatgpt and google but it didn’t help.
i try make script when open setting user can back to previous scene and not to menu
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class Exit : MonoBehaviour
{
// Variable to store the name of the previous scene
private string previousScene;
// Function to quit the application
public void QUIT()
{
Application.Quit();
Debug.Log("Quitting...");
}
// Function to switch to the settings scene, storing the current scene as the previous one
public void ChangeToSettingsScene()
{
// Store the current active scene name as the previous scene
PlayerPrefs.SetString("lastSceneName"); // to save current scene before loading next one
Debug.Log("Saving...");
SceneManager.LoadScene("settings");
}
// Function to return to the previous scene from the settings scene
public void ReturnToPreviousScene()
{
// to save current scene before loading next one
SceneManager.LoadScene(PlayerPrefs.GetString("lastSceneName")); // load previously saved scene
}
// Function to switch to the menu scene
public void ChangeToMenuScene()
{
SceneManager.LoadScene("menu");
}
// Function to start the game by loading the game scene
public void PlayGame()
{
SceneManager.LoadScene("game");
}
}