diff --git a/Game/Assets/Scripts/MenuManager.cs b/Game/Assets/Scripts/MenuManager.cs new file mode 100644 index 0000000..a90a7c3 --- /dev/null +++ b/Game/Assets/Scripts/MenuManager.cs @@ -0,0 +1,107 @@ +/* +* Author: Reza +* Date: 30/11/2024 +* Description: Contains main menu functions like Start, Quit, and changes panels when setting +and How To Play buttons are pressed. +*/ + +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; +using UnityEngine.UI; +using TMPro; + +public class MenuManager : MonoBehaviour +{ + /// + /// UI and audio references + /// + public GameObject mainMenuPanel; + public GameObject howToPlayPanel; + public GameObject settingsPanel; + public AudioSource backgroundMusicSource; + public Slider volumeSlider; + + private void Awake() + { + // Set initial slider value + if (volumeSlider != null && backgroundMusicSource != null) + { + volumeSlider.value = backgroundMusicSource.volume; + } + + // Listener to the slider's value change event + volumeSlider.onValueChanged.AddListener(OnVolumeSliderChanged); + } + + // Start is called before the first frame update + void Start() + { + howToPlayPanel.SetActive(false); + settingsPanel.SetActive(false); + } + + /// + /// Main menu button functions + /// + //When start button is pressed + public void StartGame() + { + SceneManager.LoadScene(1); + } + + //When "?" button is pressed, show only how to play panel + public void HowToPlay() + { + mainMenuPanel.SetActive(false); + howToPlayPanel.SetActive(true); + settingsPanel.SetActive(false); + } + + //When settings button is pressed, show only settings panel + public void Settings() + { + mainMenuPanel.SetActive(false); + howToPlayPanel.SetActive(false); + settingsPanel.SetActive(true); + } + + //When quit button is pressed, game closes + public void QuitGame() + { + Application.Quit(); + } + + //When back button is pressed, shows only main menu + public void Back() + { + mainMenuPanel.SetActive(true); + howToPlayPanel.SetActive(false); + settingsPanel.SetActive(false); + } + + /// + /// Set volume for BG music + /// + /// + public void SetVolume(float volume) + { + if (backgroundMusicSource != null) + { + backgroundMusicSource.volume = volume; + } + } + + /// + /// When volume slider value changes, this function is called + /// + /// + private void OnVolumeSliderChanged(float value) + { + if (backgroundMusicSource != null) + { + backgroundMusicSource.volume = value; + } + } +} diff --git a/Game/Assets/Scripts/MenuManager.cs.meta b/Game/Assets/Scripts/MenuManager.cs.meta new file mode 100644 index 0000000..a3bac0e --- /dev/null +++ b/Game/Assets/Scripts/MenuManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 703195f04468f364db1bbdc8d95a0528 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: