- Home /
press esc to show a GUI menu
Hello
I wrote currently a game code, but im stuck with a big problem. I want that, when the esc key is pressed, the menu is showed.
That is my hierarchy:
Canvas
Panel
TextScore // to show the score on the screen
FinishMenu // when the level is complete
QuitButton
MenuButton
NextButton
EscapeMenu // whenn you press esc key, menu is showed
QuitButton
MenuButton
ReplayButton
ContinueButton
FallDownMenu // when the player die, the menu is showed
QuitButton
MenuButton
ReplayButton
PauseButtonImage // Image ( || ) for pause on the screen
a) when the level is complete, a menu is showed with differents buttons like in the hierarchy. it works
b) when the player (gameObject) dies, a menu is showed. It works like a)
c) But while you play and try the esc key, the game is paused but the menu is not showed that is the code
public GameObject escapeMenues;
public bool isPaus;
private int escCount = 0;
public Text textScoreText;
public Text topScoreTop;
void Start()
{
isPaus = false;
escapeMenues.SetActive(false);
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape) && escCount == 0)
{
setPause();
SetCountText();
escapeMenues.SetActive(true);
escCount = 1;
}
if (Input.GetKeyDown(KeyCode.Escape) && escCount == 1)
{
setPause();
escapeMenues.SetActive(false);
escCount = 0;
}
}
public void loadNaechsteLevel()
{
//Application.LoadLevel(_levelName);
Application.LoadLevel(Application.loadedLevel + 1);
}
public void loadSelbeLevel()
{
Application.LoadLevel(Application.loadedLevel);
}
public void loadMenu()
{
Application.LoadLevel("Menus");
}
public void VerlasseDasSpiel()
{
Application.Quit();
}
public void setPause()
{
if (!isPaus)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
isPaus = !isPaus;
}
void SetCountText()
{
textScoreText.text = RotateSphere.countPickUp.ToString();
topScoreTop.text = RotateSphere.topScore.ToString();
}
I assigned public GameObject escapeMenues with EscapeMenu in my hierarchy
I also tried to debug it. I wrote some Debug.Log(); in to if (Input.GetKeyDown(KeyCode.Escape) && escCount == 0). It works of cause, then the game is paused but the menu is not showed.
The plattform is android
Please i need you help, thank you !!
Can you share the code that does work? The one used when the player completes the game or dies.
Are you sure Canvas and Panel are active? escape$$anonymous$$enues.SetActive(true); should make that object visible again.
Also, you said it's an Android project, does it work in the editor but not in Android or fails in both?
Answer by MakakWasTaken · Sep 08, 2015 at 06:45 PM
You could try this instead:
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
setPause();
SetCountText();
}
}
public void setPause()
{
if (!isPaus)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
isPaus = !isPaus;
escapeMenus.SetActive(isPause);
}
You mean 22. escape$$anonymous$$enus.SetActive(false); it doesnt work !!
I think the application is good !! i've done something like
void Update()
{
if (Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.Escape))
{
setPauseEscape();
}
}
public void setPauseEscape()
{
if (!isPause)
{
Time.timeScale = 0;
escape$$anonymous$$enues.SetActive(true);
}
else
{
Time.timeScale = 1;
escape$$anonymous$$enues.SetActive(false);
}
isPause = !isPause;
}
i didnt know why setActive dont work in update() Ths for help !!
Answer by CoreApp2 · Sep 09, 2015 at 09:41 AM
This is how the scene window look
![t][1]
and the game window
!
and the code that work with the other menu
public Text winText;
public Text textScoreText;
public Text topScoreTop;
public GameObject imageScore;
public bool isPaus;
// Use this for initialization
void Start () {
winText.text = "";
isPaus = false;
imageScore.SetActive(false);
}
// Update is called once per frame
void Update () {
}
IEnumerator OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
winText.text = "Level Complete!";
Destroy(other.gameObject);
yield return new WaitForSeconds(2);
Destroy(winText);
SetCountText();
imageScore.SetActive(true);
}
}
void SetCountText()
{
textScoreText.text = RotateSphere.countPickUp.ToString();
topScoreTop.text = RotateSphere.topScore.ToString();
}
public void VerlasseDasSpiel()
{
Application.Quit();
}
public void setPause()
{
if (!isPaus)
{
Time.timeScale = 0;
}
else
{
Time.timeScale = 1;
}
isPaus = !isPaus;
}
public void loadNaechsteLevel()
{
Application.LoadLevel(Application.loadedLevel + 1);
}
public void loadSelbeLevel()
{
Application.LoadLevel(Application.loadedLevel);
}
public void loadMenu()
{
Application.LoadLevel("Menus");
}
On the smartphone the pause and esc button doesnt work and when i touch on the screen, it seems to pause the game rather than jump. Maybe it is the gui. But i think what ive done with the gui is correct. I already spent a lot of time with it. Pls i need u help !
Your answer
Follow this Question
Related Questions
Main Menu - One scene or multiple? 1 Answer
Problem with multi touch 1 Answer
Store/Stack Items 0 Answers
Does GUI stays on the same place no mather the device? 0 Answers
Vector3 to float[ScreenToWorldPoint] 0 Answers