topical media & game development

talk show tell print

lib-unity-book-08-MainMenuGUI2-ch-8.js / js



  /* Script Provided by Will Goldstone as part of Unity Game Development Essentials book assets */
  /* Please Do Not Remove this comment - this script is for reference only */
  var beep : AudioClip;
  var menuSkin : GUISkin;
  var areaWidth : float;
  var areaHeight : float;
  
  function OnGUI(){
          
          GUI.skin = menuSkin;
          
          var ScreenX = ((Screen.width * 0.5) - (areaWidth * 0.5));
          var ScreenY = ((Screen.height * 0.5) - (areaHeight * 0.5));
          
          GUILayout.BeginArea (Rect (ScreenX,ScreenY, areaWidth, areaHeight));
          
          if(GUILayout.Button ("Play")){
                  
                  OpenLevel("Island Level");
          }
          
          if(GUILayout.Button ("Instructions")){
                  OpenLevel("Instructions");
          }
  
          if(GUILayout.Button ("Quit")){        
                  Application.Quit();        
          }
  
          GUILayout.EndArea();        
  }                
  
  function OpenLevel(level : String){
                  audio.PlayOneShot(beep);
                  yield new WaitForSeconds(0.35);
          
                  Application.LoadLevel(level);        
  }
  @script RequireComponent(AudioSource)


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.