The essence of this, I saw the procedural generation of the level of the finished rooms / modules.


Block example


What are some ways to connect rooms? So that the next room is automatically attached to the right of the previous one.

Example

Thank you in advance!

    2 answers 2

    enter image description here

    black rectangles are our initial map, we know the size of the modules, we know the left border and the right one (x1 and x2 below)

    Further, as needed, let's spawn the rest of the modules in x coordinates and immediately, when spawning a new module, change x1 or x2 so that the next module will fall into place

    Ps change x - coordinates can be depending on different modules, for example through a switch, tk the length of the modules can differ

      I did that. In the update, if the camera position in x is greater than BG1 plus how many units it is (so that BG1 does not Teleport in advance), change the position relative to the initial position.x

      using System.Collections; using System.Collections.Generic; using UnityEngine; public class TileBG : MonoBehaviour { public Transform BG1;//кидаете сюда 1 Background public Transform BG2;// public Transform cam;//камера private void Start() { } void Update() { if (cam.position.x > BG1.localPosition.x + 2.4f){ BG1.localPosition = new Vector3(BG1.localPosition.x + 4f, 0, 0); } if (cam.position.x > BG2.localPosition.x + 1.5f) { BG2.localPosition = new Vector3(BG2.localPosition.x + 4f, 0, 0); } } 

      }

      • Why is it that you compare localPosition and worldPosition? It is easy to invent an example that breaks this code. Moreover, if-else is absolutely not expandable for the n-th number of different rooms. - RiotBr3aker