Need Help with Physics.Checkbox

Hello Guys,

I’m trying to code my own DungeonGenerator but I ran in to some problems already^^
(the red blocks are the Doors)
In the first Pic you can see how the room looks like without corridors attached to it.

In the second Pic you can see what happened when I wanted to attach the corridors with the Code.

In the third Pic you can see how it should look ^^

I hope you can help me :slight_smile:

The CODE :

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

public class GenerateCorrs : MonoBehaviour {
    public GameObject me;
   private Vector3 pos;
    public GameObject[] gang;
 
    // Use this for initialization
    void Start () {
        foreach(Transform child in transform)
        {
          
            if (child.tag == "Door_Block") //The Red Blocks are the "DoorBlocks" and are tagged "Door_Block"
            {
                Debug.Log("Child Found!!!");
                pos = child.transform.position; //Here I get the position of the Door_Block
                if (FreeSpaceAt(-1, 1,pos) & FreeSpaceAt(1, 1,pos))
                {
                    Instantiate(gang[1], new Vector3(pos.x, pos.y, pos.z + 2), gang[1].transform.rotation);


                }
                if (FreeSpaceAt(-1, 1,pos) & FreeSpaceAt(-1, 0,pos) & FreeSpaceAt(-1, -1,pos))
                {
                    Instantiate(gang[0], new Vector3(pos.x - 2, pos.y, pos.z), gang[0].transform.rotation);
                    //this.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                if (FreeSpaceAt(1, 1,pos) & FreeSpaceAt(1, 0,pos) & FreeSpaceAt(1, -1,pos))
                {
                    Instantiate(gang[0], new Vector3(pos.x + 2, pos.y, pos.z), gang[0].transform.rotation);
                    ///this.transform.rotation = Quaternion.Euler(0, 0, 0);
                }
                if (FreeSpaceAt(-1,-1,pos)&FreeSpaceAt(1,-1,pos))
                {
                    Instantiate(gang[1], new Vector3(pos.x, pos.y, pos.z-2), gang[1].transform.rotation);
                    //this.transform.rotation = Quaternion.Euler(0, 270, 0);
                }
            }

        }
    }
  
    // Update is called once per frame
    void Update () {
      
    }
  
    public static bool FreeSpaceAt(int Xx, int Zz, Vector3 posi) //This Function should check where there are free blocks to show where to put a corridor
    {

        if (Physics.CheckBox(new Vector3(posi.x + Xx, 0, posi.z + Zz), new Vector3(1, 0, 1), Quaternion.identity, 1, QueryTriggerInteraction.UseGlobal))
        {
            Debug.Log("true!");
            return false;
        }
        else
        {
            Debug.Log("false:(");
            return true;
        }
    }

}



what is the difference between gang[0] and gang[1]?

gang[0] is horrizontaly and gang[1] is verticaly

I’m pretty sure it has something to do with horrizontal and vertical gangs beeing mixed.
Can’t tell you where exactly this code is kinda hard to get behind without seeing the project.

Here you can download the package of my project : Microsoft OneDrive

But I’m pretty shure that the problem should be somewhere in my FreeSpaceAt() function… but I can`t find any error or so ^^