- Home /
When I pop-up the Canvas using keyboard, That code doesn't operate.(Unity 5)
When I make a game ,I made pause menu.
Code is below. using UnityEngine; using UnityEngine.UI; using System.Collections;
public class PauseMenu : MonoBehaviour {
public Canvas pauseMenu;
public Button resume;
public Button restart;
public Button changeMode;
public Button Quit;
private bool pressPauseMenu = false;
// Use this for initialization
void Start () {
pauseMenu = pauseMenu.GetComponent<Canvas>();
resume = resume.GetComponent<Button>();
restart = restart.GetComponent<Button>();
changeMode = changeMode.GetComponent<Button>();
Quit = Quit.GetComponent<Button>();
}
void PressPkey()
{
resume.enabled = true;
restart.enabled = true;
changeMode.enabled = true;
Quit.enabled = true;
}
public void Pressresume()
{
pauseMenu.enabled = false;
}
public void Pressrestart(string scenename)
{
pauseMenu.enabled = false;
Application.LoadLevel(scenename);
}
public void PresschangeMode(string scenename)
{
pauseMenu.enabled = false;
Application.LoadLevel(scenename);
}
public void pressquit()
{
Application.Quit();
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.P))
{
pauseMenu.enabled = true;
PressPkey();
}
}
} but, If I press P, pauseMenu is not pop-up. I don't know what to do. Is the code wrong?
Comment
Do you get a NullReferenceWxception Error? If so in which line? Is your Pause$$anonymous$$enu Canvas Component disabled from the Beginning?
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How do I obtain children on UI canvas text 0 Answers
Create Unity UI Panel via Script 1 Answer