lunes, 23 de diciembre de 2013

04 Menu de pausa basico

Vamos a realizar un script muy sencillo que habra un menu de pausa al apretar la tecla P utilizando javascript.
Link al final del post
Primero definimos las variables:
    var mainMenuSceneName : String; Escena principal
    var pauseMenuFont : Font; Tipo de letra del menu de pausa
    private var pauseEnabled = false; Cuando empieza el juego el menu no es 
visible
    var MyGuiSkin: GUISkin; skin Para los botones
    var fondo : GameObject; fondo del menu
Despues con la funcion start definimos el volumen del juego como activado
y el tiempo normal
    function Start(){
    pauseEnabled = false;
    Time.timeScale = 1;
    AudioListener.volume = 1;
    Screen.showCursor = false; Si queremos que se vea el cursor ponerlo en true
Si se presiona la tecla P se detendra el juego, el volumen baja a 0.
Para hacer eso se necesita la funcion Update
function Update(){
        boton que llama el menu
 if(Input.GetKeyDown("p")){
 if(pauseEnabled == false){
   pauseEnabled = true;
   AudioListener.volume = 0;
   Time.timeScale = 0;
   Screen.showCursor = true;
  }}}
 Y el resto del script lo pongo tal cual ya que es bastante simple y solo se
 necesita saber un poco de javascript

private var showGraphicsDropDown = false;

     function OnGUI () {

GUI.skin = MyGuiSkin;                     
GUI.skin.box.font = pauseMenuFont;
GUI.skin.button.font = pauseMenuFont;


if(pauseEnabled == true){

// fondo del menu


     fondo.gameObject.active = true;

 

 
 // botones del menu
 
 // Resumen

  if(GUI.Button(Rect(Screen.width /2 - 150,Screen.height /2 - 110,250,50), "Resumen")){
   //Vuelve al juego
     
  if(pauseEnabled == true){
   
  fondo.gameObject.active = false;
   
   pauseEnabled = false;
   Time.timeScale = 1;
   AudioListener.volume = 1;
   Screen.showCursor = false;   
  }

   
  }

 
 
 
 
 
// boton calidad visual del juego 
if(GUI.Button(Rect(Screen.width /2 - 150,Screen.height /2 - 60 ,250,50), "Calidad Grafica")){
if(showGraphicsDropDown == false){
showGraphicsDropDown = true;
}
else{
showGraphicsDropDown = false;
}}
//funcion para la calidad de imagen del juego
if(showGraphicsDropDown == true){
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 ,250,50), "Fastest")){
QualitySettings.currentLevel = QualityLevel.Fastest;
}
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 + 50,250,50), "Fast")){
QualitySettings.currentLevel = QualityLevel.Fast;
}
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 + 100,250,50), "Simple")){
QualitySettings.currentLevel = QualityLevel.Simple;
}
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 + 150,250,50), "Good")){
QualitySettings.currentLevel = QualityLevel.Good;
}
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 + 200,250,50), "Beautiful")){
QualitySettings.currentLevel = QualityLevel.Beautiful;
}
if(GUI.Button(Rect(Screen.width /2 - 500,Screen.height /3.5 + 250,250,50), "Fantastic")){
QualitySettings.currentLevel = QualityLevel.Fantastic;
}
   
if(Input.GetKeyDown("escape")){
showGraphicsDropDown = false;
}}
// volver a menu principal
if(GUI.Button(Rect(Screen.width /2 - 150,Screen.height /2 - 10,250,50), "Volver a menu principal" )){
Application.LoadLevel(mainMenuSceneName);}
// salir del juego
if (GUI.Button (Rect (Screen.width /2 - 150,Screen.height /2 +40,250,50), "Salir del juego")){
Application.Quit();
}}}
Link: http://www.mediafire.com/download/16xc3o74l5a4xvx/Menu+Pausa.rar

2 comentarios:

  1. Hola, todo funciona bien pero los Objetos siguen funcionando, hay alguna forma de hacer que pare todo al 100%?

    ResponderEliminar
  2. Tienes que hacer un pequeño cambio que al apretar la tecla "p"se cargue otra escena diferente y al volver al juego se vuelva a cargar tu escena.
    Otra cosa diferente es volver al juego
    Donde lo dejastes que ya es mas complicado.

    ResponderEliminar