Multiple buttons when one is on turn the other off

hi, I am trying to write a code to attach to multiple UI buttons that basically turns on the hidden objects. I have it working for turning on the object but i want the next section of code to hide the object again when a different button is clicked. Basically its a preview screen, so you can click on each piece and it will show you and when you go to look at the next one it hides the first and shows the second.

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.UI;

public class gameObjectOpen : MonoBehaviour

{

public GameObject unit;
public void OpenObject()
{
    if (unit != null)
    {
        unit.SetActive(true);
    }
}
 void update(){
     if ( //"I dont know what to put here" ){
         unit.SetActive(false);
     }

 }

}

Following code not tested:

UnitToggle.cs

Meant to replace your current gameObjectOpen script

using UnityEngine;

public class UnitToggle : MonoBehaviour
{
    // Drag & drop the gameObject with the `UnitToggleGroup` component (see below)
    public UnitToggleGroup unitToggleGroup;
    public GameObject unit;
    public event System.Action<GameObject> ObjectOpened;

    void Start()
    {
        unitToggleGroup.Add(this);
    }

    public void OpenObject()
    {
        if (unit != null)
        {
            unit.SetActive(true);
            ObjectOpened?.Invoke(unit);
        }
    }
    public void CloseObject()
    {
        if (unit != null)
            unit.SetActive(false);
    }
}

UnitToggleGroup.cs

To be put on a parent game object

using System.Collections.Generic;
using UnityEngine;

public class UnitToggleGroup : MonoBehaviour
{
    private List<UnitToggle> toggles = new List<UnitToggle>();

    public GameObject SelectedUnit { get ; private set ; }

    public void Add(UnitToggle toggle)
    {
        if(toggles.Contains(toggle))
            return;

        toggles.Add(toggle);
        toggle.ObjectOpened += (GameObject unit) => OnObjectEnabled(toggle, unit);
    }
    public void OnObjectEnabled(UnitToggle selectedToggle, GameObject unit)
    {
        foreach(UnitToggle toggle in toggles)
        {
            if(toggle != selectedToggle)
                toggle.CloseObject();
        }
        SelectedUnit = unit;
    }
}

Spawner.cs

(According to the extra need posted in the comments)

public class Spawner : MonoBehaviour
{
    public UnitToggleGroup unitToggleGroup;
    public Transform[] spawnLocations;

    void OnBecameVisible()
    {
        if(unitToggleGroup.SelectedUnit != null)
            GameObject unit = Instantiate(unitToggleGroup.SelectedUnit, spawnLocations[Random.Range(0, spawnLocations.Length)].transform.position, Quaternion.Euler(0,0,0)) as GameObject;
    }
}