buttons appear and disappear

Hello everyone, I am using this code to open a door below by entering a code:

function Update () {
}var doorCode : String = “casa”;
var stringToEdit : String;
var buttonMessage : String = “Digite Código”;
function OnGUI(){
stringToEdit = GUI.TextField (Rect (20, 100, 70, 25), stringToEdit, 4);
if(stringToEdit == doorCode){
buttonMessage = “Abrir Bau”;
}else{
buttonMessage = “Digite Código”;
}
if(GUI.Button(Rect(95, 100, 120, 25), buttonMessage) && stringToEdit == doorCode){
transform.Rotate(-90,0,0);
}
}

I would like to add some element to the script to make the buttons appear when the player enters the room and disappear when the player leaves. thank you

Set a trigger that sets a boolean when the player passes through it, and only show the buttons if the boolean is true. Something like:

function OnTriggerEnter(other: collider)
{
    if (other.CompareTag("Player"))
        showButtons = !showButtons;
}

function OnGUI()
{
    if (showButtons)
        //your code
}

Also, please please please format your code next time. You just mark it and click the code button - the one with binary digits on it. Or hit ctrl+K, that’s working too.