I have an “Exit to Menu” button on my pause screen to load the main menu. When I am in the Unity editor and testing the game, the script works fine. However, whenever I build the game, clicking the “Exit to Menu” button just closes the application.
I have both scenes included in the build (it starts on the main menu screen and clicking the play button brings up my main game scene, so I am positive both scenes are included). Does anyone have any idea what might be causing this issue? I have my code below. In the editor, I filled out public string “sceneName” as Main Menu, the name of the main menu scene.
`using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.SceneManagement;
public class LoadScene : MonoBehaviour
{
public string sceneName;
void Start()
{
}
void Update()
{
if (EventSystem.current.IsPointerOverGameObject())
{
if (Input.GetMouseButtonUp(0))
{
SceneManager.LoadScene(sceneName);
}
}
}
}`
Thank you for your help!