Flickering pause menu c#

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);
        }
    }


}

Hello i ended up fixing it just made a stupid mistake in my hierarchy fixed it and now its working fine. I will move onto creating the functionality for my buttons.

Thanks for the help.

The script looks actually correct. Is the pausemenuUI maybe set to inactive from another script also?