Hello fellow Programmers,
I started coding with Unity about 2 Weeks ago and I am currently working on making one of the tutorial projects (Roll a Ball) my own and creating it by myself. I have encountered whilst working on the pause menu something I don’t really understand so I have to ask here:
I tried this first, but it didn’t work (No compiler errors!) so I tried it with a button which then worked (I want it to be accessed through the key “Escape” as well)
public GameObject PauseMenu;
void Start () {
PauseMenu.SetActive (false);
}
void Update ()
{
if(Input.GetKeyDown(KeyCode.Escape)) {
if(Time.timeScale == 1) {
Time.timeScale = 0;
PauseMenu.SetActive (true);
Cursor.visible = true;
} else {
Time.timeScale = 1;
PauseMenu.SetActive (false);
Cursor.visible = false;
}
}
}
here the working code, binded to a button:
public GameObject PauseMenu;
void Start () {
PauseMenu.SetActive (false);
}
public void PauseButton()
{
if (Time.timeScale == 1) {
PauseMenu.SetActive (true);
Time.timeScale = 0;
Cursor.visible = true;
}
else
{
PauseMenu.SetActive (false);
Time.timeScale = 1;
Cursor.visible = false;
}
}
I thank anybody for their help!
Happy coding