script for restar button in unity

in my game after losing a level shows the restart button of the level . and the question is how to create a script that will show the restart button for example 3 times and after the fourth unsuccessful attempt will not show it anymore
this is my script to call the button:

 else 
        {
            yield return new WaitForSecondsRealtime(0.5f);
            GameUI.ShowRestartButton();

and this is the button script:

public GameObject log2;
    public void ShowRestartButton()
    {
        
        
        Destroy(log2.gameObject);
        Image2.SetActive(true);
        

    }

Try using a simple variable outside the function to keep track of how many times the restart screen showed up

public GameObject log2;
private int deaths = 0;
public void ShowRestartButton() {
    if(deaths < 3) {
        Destroy(log2.gameObject);
        deaths++;
        Image2.SetActive(true);
    }
}

@Pywona
I did something like this

public GameObject logC;
    private int deaths = 0;
    public void ContinueGame()

    {
        if (deaths < 3)
        {
            Destroy(logC.gameObject);
            deaths++;
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
        }
            
    }

because I’m mainly talking about the continue game button, which after three failed attempts disappears and tells the player to restart the game, but it doesn’t work and the button keeps showing up. Destroy LogC is that button