How can I use this script only when i press the esc key ?
using UnityEngine;
using System.Collections;
public class Menu : MonoBehaviour
{
public GUISkin guiSkin;
public Texture2D background, LOGO;
public bool DragWindow = false;
public string chargerLeNiveau = "";
public string chargerLeNiveau2 = "";
public string chargerLeNiveau3 = "";
public string chargerLeNiveau4 = "";
public string[] AboutTextLines = new string[0];
private string clicked = "", MessageDisplayOnAbout = "A propos
";
private Rect WindowRect = new Rect((Screen.width / 2) - 200, Screen.height / 2, 150, 200);
private float volume = 1.0f;
private void Start()
{
for (int x = 0; x < AboutTextLines.Length;x++ )
{
MessageDisplayOnAbout += AboutTextLines[x] + "
";
}
MessageDisplayOnAbout += "
Appuyer sur Esc pour revenir en arriere";
}
private void OnGUI()
{
// si escape est appuyé
if (Input.GetKeyDown (KeyCode.Escape))
{
if(!isMenuOpen)
{
// open menu
isMenuOpen = true;
}
else
{
// close menu
isMenuOpen = false;
}
}
}
if (background != null)
GUI.DrawTexture(new Rect(0,0,Screen.width , Screen.height),background);
if (LOGO != null && clicked != "A propos")
GUI.DrawTexture(new Rect((Screen.width / 2) - 100, 30, 200, 200), LOGO);
GUI.skin = guiSkin;
if (clicked == "")
{
WindowRect = GUI.Window(0, WindowRect, menuFunc, "Menu general");
}
else if (clicked == "Options")
{
WindowRect = GUI.Window(1, WindowRect, optionsFunc, "Options");
}
else if (clicked == "A propos")
{
GUI.Box(new Rect (0,0,Screen.width,Screen.height), MessageDisplayOnAbout);
}else if (clicked == "Resolution")
{
GUILayout.BeginVertical();
for (int x = 0; x < Screen.resolutions.Length;x++ )
{
if (GUILayout.Button(Screen.resolutions[x].width + "X" + Screen.resolutions[x].height))
{
Screen.SetResolution(Screen.resolutions[x].width,Screen.resolutions[x].height,true);
}
}
GUILayout.EndVertical();
GUILayout.BeginHorizontal();
if (GUILayout.Button("Retour"))
{
clicked = "Options";
}
GUILayout.EndHorizontal();
}
}
}
private void optionsFunc(int id)
{
if (GUILayout.Button("Resolution"))
{
clicked = "Resolution";
}
GUILayout.Box("Volume");
volume = GUILayout.HorizontalSlider(volume ,0.0f,1.0f);
AudioListener.volume = volume;
if (GUILayout.Button("Retour"))
{
clicked = "";
}
if (DragWindow)
GUI.DragWindow(new Rect (0,0,Screen.width,Screen.height));
}
private void menuFunc(int id)
{
// si escape est appuyé
if (Input.GetKeyDown (KeyCode.Escape))
{
//Boutons
if (GUILayout.Button("Lancer le jeu"))
{
//Lancer le jeu si cliquer
Application.LoadLevel(chargerLeNiveau);
}
if (GUILayout.Button("Lancer le jeu 2"))
{
//Lancer le jeu 2 si cliquer
Application.LoadLevel(chargerLeNiveau2);
}
if (GUILayout.Button("Lancer le jeu 3"))
{
//Lancer le jeu 3 si cliquer
Application.LoadLevel(chargerLeNiveau3);
}
if (GUILayout.Button("Lancer le jeu 4"))
{
//Lancer le jeu 4 si cliquer
Application.LoadLevel(chargerLeNiveau4);
}
if (GUILayout.Button("Options"))
{
clicked = "Options";
}
if (GUILayout.Button("A propos"))
{
clicked = "A propos";
}
if (GUILayout.Button("Quitter"))
{
Application.Quit();
}
if (DragWindow)
GUI.DragWindow(new Rect(0, 0, Screen.width, Screen.height));
}
}
private void Update()
{
if (clicked == "A propos" && Input.GetKeyDown (KeyCode.Escape))
if(!isMenuOpen)
{
// open menu
isMenuOpen = true;
}
else
{
// close menu
isMenuOpen = false;
}
}
}