Files
blackhole-escape/Assets/Assets_And_Scenes/Scripts/Other Scripts/MainMenuScript.cs
2022-06-18 15:55:39 +01:00

89 lines
2.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenuScript : MonoBehaviour
{
public BackgroundMusicManager currentBGMManager;
public MenuAudioManager currentMenuAudioManager;
private void Start()
{
// If the BGM manager is present, queue up and play the given track index
if (currentBGMManager)
{
currentBGMManager.StartAudioQueueAndPlay(0);
}
}
public void SetupVolumeOptions()
{
// Gets the volume settings from the player profile and sets it in the game
float currentMasterVol = PlayerPrefs.GetFloat("currentMasterVol");
GameObject masterVolSliderGo = GameObject.Find("Main Slider");
float currentMusicVol = PlayerPrefs.GetFloat("currentMusicVol");
GameObject musicVolSliderGo = GameObject.Find("Music Slider");
float currentSFXVol = PlayerPrefs.GetFloat("currentSFXVol");
GameObject SFXVolSliderGo = GameObject.Find("SFX Slider");
masterVolSliderGo.GetComponent<Slider>().value = currentMasterVol;
musicVolSliderGo.GetComponent<Slider>().value = currentMusicVol;
SFXVolSliderGo.GetComponent<Slider>().value = currentSFXVol;
}
public void PlayMenuClick()
{
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
}
public void StartGame()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
SceneManager.LoadScene("Rules");
}
public void Quit()
{
// Play the menu click sound if the audio manager is present
if (currentMenuAudioManager)
{
currentMenuAudioManager.PlayMenuClick();
}
Application.Quit();
}
public void SetMasterVolume(float value)
{
// Converts the master volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("masterVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentMasterVol", value);
}
public void SetMusicVolume(float value)
{
// Converts the music volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("musicVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentMusicVol", value);
}
public void SetSFXVolume(float value)
{
// Converts the sfx volume into decibels and stores it in the player profile
GameManager.Instance.currentAudioMixer.SetFloat("sfxVol", SharedMethods.ConvertToDecibels(value));
PlayerPrefs.SetFloat("currentSFXVol", value);
}
}