I made a pause menu but can not seem to get it to work properly. if the canvas is checked to display all i get is a pause menu that is constantly being triggered and untriggered really fast. Or it just doesn’t appear. Heres the code. Any help would be appreciated.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PauseMenu : MonoBehaviour
{
[SerializeField] private GameObject PauseMenuMain;
[SerializeField] private bool isPaused;
private void Update()
{
if (!Input.GetKeyDown(KeyCode.Escape))
{
isPaused = !isPaused;
}
if (isPaused)
{
ActivateMenu();
}
else
{
DeactivateMenu();
}
}
private void ActivateMenu()
{
PauseMenuMain.SetActive(true);
}
private void DeactivateMenu()
{
PauseMenuMain.SetActive(false);
}
}