title: Align Spawnpoints in Procedural generation
body: <p>I've created some boxes to recreate a 2D level where the dungeon is being created in a procedural generation. Altho when I run my script it creates the right levels, but it does not align the Spawnpoints to each other.</p>
  
  <p><img src="https://i.ibb.co/996rshp/Image-1.jpg" alt="Standard tile with spawnpoints"></p>
  
  <p>This causes an unlimited level generation (since the spawn points don't touch) but it also makes sure that there is no way for the character to go from 1 way to the other. I've made sure that every level is 10 x 10 and the spawn points are 10 pixels away from the middle of the rooms. I wanted to ensure collision between the spawn points but unfortunately, this is not the case.</p>
  
  <p><img src="https://i.ibb.co/FVrfvFv/Image-2.jpg" alt="Spawnpoints not touching eachother"></p>
  
  <p>I have created multiple rooms where each has their own exit (Spawn Point) depending on where the spawn point is, it can connect with another room that has the same spawn point (Room with a left exit is connected by a room with at least a right exit).</p>
  
  <p>I put all of this in an int, declaring the number of rooms that are available.</p>
  
  <p>Roomspawner code</p>
  
  <pre><code>
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class RoomSpawner : MonoBehaviour
  {
      public int openingDirection;
      // 1 --&gt; need bottom door
      // 2 --&gt; need top door
      // 3 --&gt; need left door
      // 4 --&gt; need right door
  
      private RoomTemplates templates;
      private int rand;
      private bool spawned = false;
  
      void Start(){
        templates = GameObject.FindGameObjectWithTag("Rooms").GetComponent&lt;RoomTemplates&gt;();
        Invoke("Spawn", 0.5f);
      }
  
      void Spawn(){
        if(spawned == false){
          if(openingDirection == 1){
              // Need to spawn a room with a BOTTOM door.
              rand = Random.Range(0, templates.bottomRooms.Length);
              Instantiate(templates.bottomRooms[rand], transform.position, templates.bottomRooms[rand].transform.rotation);
            } else if(openingDirection == 2){
              // Need to spawn a room with a TOP door.
              rand = Random.Range(0, templates.topRooms.Length);
              Instantiate(templates.topRooms[rand], transform.position, templates.topRooms[rand].transform.rotation);
            } else if(openingDirection == 3){
              // Need to spawn a room with a LEFT door.
              rand = Random.Range(0, templates.leftRooms.Length);
              Instantiate(templates.leftRooms[rand], transform.position, templates.leftRooms[rand].transform.rotation);
            } else if(openingDirection == 4){
              // Need to spawn a room with a RIGHT door.
              rand = Random.Range(0, templates.rightRooms.Length);
              Instantiate(templates.rightRooms[rand], transform.position, templates.rightRooms[rand].transform.rotation);
            }
            spawned = true;
        }
  
        void OnTriggerEnter2D(Collider2D other){
          if(other.CompareTag("SpawnPoint")){
            if(other.GetComponent&lt;RoomSpawner&gt;().spawned == false &amp;&amp; spawned == false){
              // spawns walls blocking off any opening !
              Instantiate(templates.closedRoom, transform.position, Quaternion.identity);
              Destroy(gameObject);
            }
            spawned = true;
          }
      }
    }
  }
  
  </code></pre>
  
  <p>Room templates</p>
  
  <pre><code>
  using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class RoomTemplates : MonoBehaviour
  {
      public GameObject[] bottomRooms;
      public GameObject[] topRooms;
      public GameObject[] leftRooms;
      public GameObject[] rightRooms;
  
      public GameObject closedRoom;
  }
  </code></pre>
  
  <p>I did a new test with a room where it has only 1 spawn point. I Paused the game the second the 2nd spawn point was created so you can see that the 2nd level is created a with a different height than the starting one.</p>
  
  <p><img src="https://i.ibb.co/82Hh10N/image-3.jpg" alt="First room"></p>
  
  <p>Underneath you can see the connecting room spawning just above the starting one. By doing this it messes up all the rest of the rooms.</p>
  
  <p><img src="https://i.ibb.co/L976VYL/image-4.jpg" alt="Second room different height"></p>
  
  <p>Instead I want it to be like this</p>
  
  <p><img src="https://i.ibb.co/R2JFrY2/image-5.jpg" alt="Perfect room"></p>