Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class menuScript : MonoBehaviour
- {
- public Canvas optionsMenu;
- public Canvas quitMenu;
- public Button startText;
- public Button optionsText;
- public Button quitText;
- public Slider slider;
- private float cachedVolume;
- private bool audioMuted = false;
- //the initial values for application launch, note that the quit and option menus are off by default
- void Start()
- {
- quitMenu = quitMenu.GetComponent<Canvas> ();
- optionsMenu = optionsMenu.GetComponent<Canvas> ();
- startText = startText.GetComponent<Button> ();
- optionsText = optionsText.GetComponent<Button>();
- quitText = quitText.GetComponent<Button> ();
- quitMenu.enabled = false;
- optionsMenu.enabled = false;
- }
- //update is called once per frame
- void Update()
- {
- if (!audioMuted)
- {
- AudioListener.volume = slider.value;
- }
- }
- //toggles global audio mute on and off.
- public void MuteAudio()
- {
- if (!audioMuted)
- {
- audioMuted = true;
- slider.enabled = false;
- cachedVolume = slider.value;
- slider.value = 0;
- AudioListener.volume = 0;
- }
- else
- {
- audioMuted = false;
- slider.enabled = true;
- slider.value = cachedVolume;
- AudioListener.volume = cachedVolume;
- }
- }
- // pauses audio
- public void PauseAudio()
- {
- AudioListener.pause = !AudioListener.pause;
- }
- // open up the options menu when clicking on options
- public void optionsPress()
- {
- optionsMenu.enabled = true;
- quitMenu.enabled = false;
- startText.enabled = false;
- optionsText.enabled = false;
- quitText.enabled = false;
- }
- //clicking on quit in the main menu, opens the quit confirmation window
- public void ExitPress()
- {
- quitMenu.enabled = true;
- optionsMenu.enabled = false;
- startText.enabled = false;
- optionsText.enabled = false;
- quitText.enabled = false;
- }
- //clicking cancel or no on options or exit menu. brings you back to main menu and reenables the main menu text
- public void NoPress()
- {
- quitMenu.enabled = false;
- optionsMenu.enabled = false;
- startText.enabled = true;
- optionsText.enabled = true;
- quitText.enabled = true;
- }
- /* clicking on play starts level 1 test map
- * should eventually send player to character select
- * and map select screen
- */
- public void StartLevel()
- {
- Application.LoadLevel(1);
- }
- //when confirming game quit, closes the application, on unity game scene window, this doesn't do anything
- // this is normal.
- public void ExitGame()
- {
- Application.Quit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement