game(scripts): main menu manager
This commit is contained in:
parent
9cc96fdcc6
commit
d7e6fc6edc
107
Game/Assets/Scripts/MenuManager.cs
Normal file
107
Game/Assets/Scripts/MenuManager.cs
Normal file
|
@ -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
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// UI and audio references
|
||||||
|
/// </summary>
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Main menu button functions
|
||||||
|
/// </summary>
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Set volume for BG music
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="volume"></param>
|
||||||
|
public void SetVolume(float volume)
|
||||||
|
{
|
||||||
|
if (backgroundMusicSource != null)
|
||||||
|
{
|
||||||
|
backgroundMusicSource.volume = volume;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// When volume slider value changes, this function is called
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="value"></param>
|
||||||
|
private void OnVolumeSliderChanged(float value)
|
||||||
|
{
|
||||||
|
if (backgroundMusicSource != null)
|
||||||
|
{
|
||||||
|
backgroundMusicSource.volume = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
11
Game/Assets/Scripts/MenuManager.cs.meta
Normal file
11
Game/Assets/Scripts/MenuManager.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 703195f04468f364db1bbdc8d95a0528
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Loading…
Reference in a new issue