Advertisement
Guest User

null reference exception line 33

a guest
Jun 29th, 2015
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.55 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. using System.Collections;
  4.  
  5. public class menuScript : MonoBehaviour
  6. {
  7.     public Canvas optionsMenu;
  8.     public Canvas quitMenu;
  9.     public Button startText;
  10.     public Button optionsText;
  11.     public Button quitText;
  12.     public Slider slider;
  13.     private float cachedVolume;
  14.     private bool audioMuted = false;
  15.  
  16.     //the initial values for application launch, note that the quit and option menus are off by default
  17.     void Start()
  18.     {
  19.         quitMenu = quitMenu.GetComponent<Canvas> ();
  20.         optionsMenu = optionsMenu.GetComponent<Canvas> ();
  21.         startText = startText.GetComponent<Button> ();
  22.         optionsText = optionsText.GetComponent<Button>();      
  23.         quitText = quitText.GetComponent<Button> ();
  24.         quitMenu.enabled = false;
  25.         optionsMenu.enabled = false;
  26.     }
  27.  
  28.     //update is called once per frame
  29.      void Update()
  30.     {
  31.         if (!audioMuted)
  32.         {
  33.             AudioListener.volume = slider.value;
  34.         }
  35.     }
  36.  
  37.     //toggles global audio mute on and off.
  38.     public void MuteAudio()
  39.     {
  40.         if (!audioMuted)
  41.         {
  42.             audioMuted = true;
  43.             slider.enabled = false;
  44.             cachedVolume = slider.value;
  45.             slider.value = 0;
  46.             AudioListener.volume = 0;
  47.         }
  48.         else
  49.         {
  50.             audioMuted = false;
  51.             slider.enabled = true;
  52.             slider.value = cachedVolume;
  53.             AudioListener.volume = cachedVolume;
  54.         }
  55.     }
  56.  
  57.     // pauses audio
  58.     public void PauseAudio()
  59.     {
  60.         AudioListener.pause = !AudioListener.pause;
  61.     }
  62.  
  63.     // open up the options menu when clicking on options
  64.     public void optionsPress()
  65.     {
  66.         optionsMenu.enabled = true;
  67.         quitMenu.enabled = false;
  68.         startText.enabled = false;
  69.         optionsText.enabled = false;
  70.         quitText.enabled = false;      
  71.     }
  72.  
  73.     //clicking on quit in the main menu, opens the quit confirmation window
  74.     public void ExitPress()
  75.     {
  76.         quitMenu.enabled = true;
  77.         optionsMenu.enabled = false;
  78.         startText.enabled = false;
  79.         optionsText.enabled = false;   
  80.         quitText.enabled = false;
  81.     }
  82.  
  83.     //clicking cancel or no on options or exit menu. brings you back to main menu and reenables the main menu text
  84.     public void NoPress()
  85.     {
  86.         quitMenu.enabled = false;
  87.         optionsMenu.enabled = false;
  88.         startText.enabled = true;
  89.         optionsText.enabled = true;
  90.         quitText.enabled = true;
  91.     }
  92.  
  93.     /* clicking on play starts level 1 test map
  94.      *  should eventually send player to character select
  95.      *  and map select screen
  96.      */
  97.     public void StartLevel()
  98.     {
  99.         Application.LoadLevel(1);
  100.     }
  101.  
  102.     //when confirming game quit, closes the application, on unity game scene window, this doesn't do anything
  103.     // this is normal.
  104.     public void ExitGame()
  105.     {
  106.         Application.Quit();
  107.     }
  108. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement