How do I check for this at runtime?

I’ve been attempting to write my own script for a dungeon generator, and I’ve gotten pretty far already, but I got stumped when I tried to figure out how to properly check to see if one room spawned over the other. I did a lot of research on how to do this, but all the examples I could find weren’t what I was looking for or they were waaaaaay too complex for me to understand, at least enough to use those examples in my script. Here’s what I have currently

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

public class DungeonGenerator : MonoBehaviour
{
    public List<RoomValues> Rooms = new List<RoomValues>();

    private Vector3Int RandomRange;

    public Tilemap tilemap;
    public TileBase tile;

    private void Start()
    {
        CreateRoom();
    }

    public void CreateRoom()
    {
        for (int i = 0; i < Rooms.Count; i++)
        {
            int RandomNumberX = Random.Range(0, 60);
            int RandomNumberY = Random.Range(0, 45);
            RandomRange.Set(RandomNumberX, RandomNumberY, 0);

            for (int i2 = 0; i2 < Rooms[i].Positions.Count; i2++)
            {

                tilemap.SetTile(Rooms[i].Positions[i2] + RandomRange, tile);

            }
        }
    }
}

Also, I know there’s a lot of missing stuff in here, like hitboxes and hallways, but for now I’m just trying to get this part to work, and I know that just adding a random range to the room’s x and y position also isn’t how to get this to work properly, since there’s nothing to check and make sure the rooms spawned properly, but it’s all I’ve been able to come up with so far.

Does anyone know how to fix the issues in my script? Thanks :]

That’s really the only thing that sets dungeon creation apart from any other random number generator.

Oceans of digital ink have been spilled for decades on how to attack this extremely hard problem.

Start over on Youtube by working fully through four or five completely different approaches based on dungeon generation tutorials.

If you have good control over coordinates of the dungeon modules —-

You add the USED coordinates of the dungeon modules to a list to make sure that no dungeon module will overlay another.

Personally I would spawn the dungeon procedurally and have a darkness or line of sight mechanic with connectors and triggers that when the player pass it generates the next connection piece.

but if you do want to spawn the entire dungeon in one go then you should gain greater control over each of the coordinates used so that they are grid like and perfect and can be understood/found in terms of vector2 or vector3 reference.

Thanks! I’ll try that and I’ll do some research too