Greetings, I tried following the Brackeys tutorial on making a Pause menu, however; when I press play, the pause menu is already there and the game is not paused. This would be a minor bug, however pressing Esc makes the menu go away as it should, but then pressing it against doesen’t bring-it-up. I have skipped the step on connecting it to the “Menu”, because I can’t see a reason why wouldn’t the code work without it.
I normally avoid asking things on forums and on here, because I don’t want to bother people as long as I can figure-things-out myself, but I have spend the last three hours looking for the problem in the code and I cannot find it. It is connected to my Canvas GameObject and I have set the event functions according to the video - I have done exactly the same, except for the menu screen and the animation.
The “Placeholder” function I have tried to delete - that doesen’t fix it, but it is going to be a restart button, IF I can get it to work.
Here’s the code;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class MenuScript : MonoBehaviour
{
public static bool gameIsPaused = false;
public GameObject UImenu;
private void Start()
{
gameIsPaused = false;
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (gameIsPaused)
{
Resume();
} else
{
Pause();
}
}
}
public void Resume()
{
UImenu.SetActive(false);
Time.timeScale = 1f;
gameIsPaused = false;
}
void Pause()
{
UImenu.SetActive(true);
Time.timeScale = 0f;
gameIsPaused = true;
}
public void Placeholder()
{
}
public void QuitGame()
{
Debug.Log("Shutting Down");
Application.Quit();
}
}
Another small thing - my shadow on the text doesen’t work, probably because I am using TextMeshPro? Can somebody confirm?
Thanks for the help, if somebody sees this. It is either an easy fix and I am just too tired, or it is something out of my understanding. I am using Unity 2021.1.3f1