I am using the following code which works, But the first time i press escape nothing happens, if i press it again then the game object shows. Does anyone know why this is?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseScript : MonoBehaviour
{
public GameObject PauseMenu;
bool Paused = false;
// Start is called before the first frame update
void Start()
{
PauseMenu.gameObject.SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown("escape"))
{
if (Paused == true)
{
Time.timeScale = 1.0f;
PauseMenu.gameObject.SetActive(true);
Paused = false;
}
else
{
Time.timeScale = 0.0f;
PauseMenu.gameObject.SetActive(false);
Paused = true;
}
}
}
}