using UnityEngine; using UnityEngine.SceneManagement; public class MenuMusic : MonoBehaviour { public static MenuMusic Instance; void Awake() { if (Instance == null) { Instance = this; DontDestroyOnLoad(gameObject); SceneManager.sceneLoaded += OnSceneLoaded; GetComponent().volume = PlayerPrefs.GetFloat("musicVolume", 1f); } else { Destroy(gameObject); } } void OnSceneLoaded(Scene scene, LoadSceneMode mode) { if (scene.name == "GamePlayer") { SceneManager.sceneLoaded -= OnSceneLoaded; Destroy(gameObject); } } }