Trying to build a simple pause menu but i am having an issue with the pause menu flickering i know its because its updating every frame i just dont understand how to fix it. Please help.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Pausemenu : MonoBehaviour
{
public GameObject pausemenuUI;
public bool paused;
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.Escape))
{
paused = !paused;
}
if (paused)
{
pausemenuUI.SetActive(true);
}
else
{
pausemenuUI.SetActive(false);
}
}
}