the code when it works right should pause the game (which means setting the timescale to 0)when you press esc and bring up a pause menu. it does this, but when i press the menu button( which brings me to the main menu) and then press play(brings me to level 1) the level starts off with a timescale of 0 and i have to press esc for the game to start.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class PauseMenu : MonoBehaviour
{
public static bool GameIsPaused = false;
public GameObject pauseMenuUI;
void Start()
{
pauseMenuUI.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
if (GameIsPaused)
{
Resume();
}
else
{
Pause();
}
}
}
public void Resume()
{
pauseMenuUI.SetActive(false);
Time.timeScale = 1f;
GameIsPaused = false;
}
void Pause()
{
pauseMenuUI.SetActive(true);
Time.timeScale = 0f;
GameIsPaused = true;
}
public void LoadMenu()
{
SceneManager.LoadScene("main menu");
}
}
```