Okay, here is a setup for a map generator using room and corridor prefabs, allowing you to specify the number of rooms.
This generator works on a grid system. It starts with one room and iteratively tries to attach new corridors and rooms to existing ones in random directions until the desired number of rooms is placed or it runs out of valid spots.
How to Use:
MapGenerator.cs
inside an Assets/Scripts
folder.MapGenerator.cs
script to this GameObject.roomDimensions
is 5x5 and cellSize
is 1). Ensure its pivot is at the center.cellSize
is 1). Ensure its pivot is at the center and it's oriented along the X-axis by default (the script rotates it for vertical corridors).Room Prefabs
list in the Inspector.Corridor Prefab
slot.Number Of Rooms
to your desired quantity.Room Dimensions
(odd numbers like 5x5, 7x7 work best for centering), Corridor Length
, and Cell Size
to match your prefabs and desired scale.Generated Objects Parent
slot for better scene organization.MapGenerator
script component in the Inspector and select "Generate Map".GenerateMap()
method from another script or trigger it at runtime.You are right, that error CS0116
indicates that code is outside of a class definition. It seems the csharp
marker might have interfered, or the structure was slightly off.
Here is the corrected code for MapGenerator.cs
, ensuring all code is properly contained within the class.
This version ensures the using
statements are at the top, followed directly by the public class MapGenerator : MonoBehaviour { ... }
definition, with all methods and fields inside the class braces. I also slightly adjusted the corridor/room connection point calculation and the corridor rotation logic comments for clarity depending on your prefab's default orientation.
Okay, creating a map generator exactly like SCP: Secret Laboratory is quite complex, involving distinct zones (LCZ, HCZ, EZ, Surface), specific mandatory rooms (containment chambers, checkpoints, elevators), unique room shapes, and intricate connection logic.
This example provides a simplified, foundational approach inspired by SCP:SL's structure. It focuses on generating distinct "zones" sequentially, each using its own set of room/corridor prefabs, and connecting them at specific points (simulating elevators or major checkpoints).
Key Concepts Implemented:
Limitations of this Simplified Version:
Vector2Int
to Vector3Int
and adjusting GridToWorld
).Here's the code:
How to Set Up:
SCPSL_MapGenerator.cs
.cellSize
segment). You'll need one type per zone if you want different visuals (e.g., LCZ_Corridor
, HCZ_Corridor
). Assume the prefab's forward direction is along the +X axis.Elevator_Shaft_LCZ_to_HCZ
: This will be placed in LCZ to mark where HCZ should connect.Elevator_Shaft_HCZ_to_EZ
: Placed in HCZ.Gate_A_Connector
/ Gate_B_Connector
: Placed in EZ if you want specific exit points.Room Prefabs
list.Corridor Prefab
.Exit Connector Prefab
(e.g., for LCZ settings, assign Elevator_Shaft_LCZ_to_HCZ
). Leave empty for the final zone (EZ) if it has no specific required exit marker.Target Room Count
and default Room Dimensions
/Corridor Length
.Cell Size
.Generated Map Parent
.This provides a starting point. You'd need to enhance it significantly for a true SCP:SL clone, particularly by adding logic for mandatory room placement, more complex room shapes/connections, and actual elevator functionality.
Okay, let's modify the generator to use explicit connection points on prefabs and allow for multiple corridor types per zone.
1. Create the Connection Point Marker Script:
This simple script will be attached to GameObjects on your room prefabs to mark where corridors can connect.
How to Set Up (Updated):
ConnectionPointMarker.cs
and the updated SCPSL_MapGenerator.cs
are saved in your project (e.g., Assets/Scripts
).ConnectionPointMarker.cs
script to each of these empty GameObjects.SCPSL_MapGenerator
script.Corridor Prefab
field is now Corridor Prefabs
. Drag one or more corridor prefabs for that zone into this list. If you only have one type, just add that one.Room Prefabs
and Exit Connector Prefab
are still assigned correctly.Default Room Dimensions
is now mainly used for the initial bounding box check; the connection points dictate the actual connections.Now, the generator will look for ConnectionPointMarker
s on your rooms to determine where to branch off with corridors, and it will randomly pick from the available Corridor Prefabs
for each zone when building connections.
Gemini 2.5 Pro
No file selected