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 :]