How can I generate a wall/s?

I want to create for example 4 cubes and then to connect them all making a square but making them scaling to one direction and not two directions as by default.

The prefab variable is a Cube.

I have this old script I did long time ago. The script is working but not what I wanted.

This script create like a cube from all the walls.
How can I add some flag bool to decide if to create a kind of cube like it is now or to create a square empty square not to fill it. I mean if I want to make it like hollow.

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

public class GenerateWall : MonoBehaviour
{
    public GameObject prefab;
    public Vector3 wallsStartPosition;
    public float width = 0;
    public float height = 1;
    public float lengthX = 2;
    public float lengthZ = 2;
    public float time = 1;

    private List<GameObject> walls = new List<GameObject>();
    private IEnumerator coroutine;

    void Start()
    {
        for (int i = -2; i < 2; i++)
        {
            GameObject go = Instantiate(prefab);
            go.transform.parent = transform;
            go.tag = "Wall";
            Vector3 scale = Vector3.one;
            Vector3 adjustedPosition = wallsStartPosition;

            float sign = Mathf.Sign(i);
            if ((i * sign) % 2 == 0)
            {
                adjustedPosition.x += (lengthX * sign) / 2;
                scale.x = width;
                scale.y = height;
                scale.z *= lengthZ + width;
            }
            else
            {
                adjustedPosition.z += (lengthZ * sign) / 2;
                scale.x *= lengthX + width;
                scale.y = height;
                scale.z = width;
            }
            adjustedPosition.y -= height / 2;
            go.transform.localScale = scale;
            go.transform.localPosition = adjustedPosition;
            walls.Add(go);
        }
        coroutine = raiseWall(walls(0), height, time, 0, 100);
        StartCoroutine(coroutine);
        coroutine = raiseWall(walls(2), height, time, 0, 100);
        StartCoroutine(coroutine);
        coroutine = raiseWall(walls(1), height, time, 0, 100);
        StartCoroutine(coroutine);
        coroutine = raiseWall(walls(3), height, time, 0, 100);
        StartCoroutine(coroutine);
    }

    IEnumerator raiseWall(GameObject wall, float amount, float time, float delay, float steps)
    {
        Vector3 position = wall.transform.localPosition;
        float finalHeight = position.y + amount;

        yield return new WaitForSeconds(delay);

        while (position.y < finalHeight)
        {
            float remainingHeight = finalHeight - position.y;
            position.y += Mathf.Min(remainingHeight, amount / steps);
            wall.transform.localPosition = position;
            yield return new WaitForSeconds(time / steps);
        }
        yield break;
    }
}

The result is :

Walls

but if I want it to be like this ?

This is what I mean square