Disabling text after it was displayed when if statement is true

Hello,this is my first question here. I have a puzzle where a chest is opened once the count == 3, then i want a text to appear and say “the chest has opened”. I already have the text appearing, but i dont know how to close the message using “E” after it appears. I am not using any triggers, since the text would appear on its own.

At first i put most of my code in update(), so the text will keep on appearing, even after i successfully hid it.

This is my code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PuzzleManager : MonoBehaviour
{

public static int count = 0;
public GameObject closedChest;
public GameObject openChest;
public Image silverKey2; 

public AudioSource click;
public static bool isPlaying;

public GameObject soundUI; //the text gameobject
public static bool isOpen;
public GameObject Player;

// Start is called before the first frame update
void Start()
{
    count = 0;
    Debug.Log(count);
    closedChest.gameObject.SetActive(true);
    openChest.gameObject.SetActive(false);
    silverKey2.gameObject.SetActive(false); 
    isPlaying = false;

    Player.GetComponent<PlayerMovement>().enabled = true;
    Player.GetComponent<Animator>().enabled = true;

    soundUI.gameObject.SetActive(false);
    isOpen = false;

}

// Update is called once per frame
void Update()
{
    if(count == 3)
    {
        if (!isPlaying)
        {
            click.Play();
            isPlaying = true;
        }

        closedChest.gameObject.SetActive(false);
        openChest.gameObject.SetActive(true);
        Debug.Log("The chest opened!");

        

        if(isOpen)
        {
            if(Input.GetKeyDown(KeyCode.E))
            {
                hideText();
            }
        }
        else
        {
            showText();
        }
        
    }

  
}

void showText()
{
    isOpen = true;
    soundUI.gameObject.SetActive(true);
    Player.GetComponent<PlayerMovement>().enabled = false;
    Player.GetComponent<Animator>().enabled = false;//
}

void hideText()
{
    isOpen = false;
    soundUI.gameObject.SetActive(false);
    Player.GetComponent<PlayerMovement>().enabled = true;
    Player.GetComponent<Animator>().enabled = true;//
}

}

Hello there. Yes, this code is working properly. As you are settings “isOpen” to false, in your Update method, “showText” will actually get called as your else statement is there. I would recommend that you do this:

void Update()
 {
     if (count == 3)
     {
         if (!isPlaying)
         {
             click.Play();
             isPlaying = true;
         }
         closedChest.gameObject.SetActive(false);
         openChest.gameObject.SetActive(true);
         Debug.Log("The chest opened!");
         showText();
     }
         
     if (isOpen && Input.GetKeyDown(KeyCode.E))
     {
                 hideText();
      }  
 }