# 02 — Simple Room

Build a complete minimal room: floor, walls, ceiling, spawn point, ambient light, and an exit door. By the end of this tutorial your room will appear in the game.

---

## Step 1: Create the root object

Every room must have **one parent object** that contains everything.

1. In Unity → **File → New Scene** (or open the existing empty scene)
2. In the **Hierarchy**, right-click → **Create Empty**
3. Rename it using the convention `[bundle-name]_[RoomName]`:
   - Example: `my-pack_MainRoom`
   - The bundle name must be lowercase with hyphens
   - **This name must be unique across all mods** — always prefix with your bundle name
4. In the **Inspector**, set Position to `(0, 0, 0)`

---

## Step 2: Build the room geometry

### Floor

1. Right-click on the root object → **3D Object → Plane**
2. Inspector: Position `(0, 0, 0)`, Scale `(2, 1, 2)` — gives a ~20m × 20m floor

### Walls

Create four Cubes as children of the root object:

| Wall | Position | Scale |
|---|---|---|
| North | `(0, 2.5, 10)` | `(20, 5, 0.3)` |
| South | `(0, 2.5, -10)` | `(20, 5, 0.3)` |
| East | `(10, 2.5, 0)` | `(0.3, 5, 20)` |
| West | `(-10, 2.5, 0)` | `(0.3, 5, 20)` |

### Ceiling

Another Cube: Position `(0, 5, 0)`, Scale `(20, 0.3, 20)`

### Exit opening

The exit door needs a gap in one wall. Split the north wall into two Cubes:

- Remove the single north wall Cube
- **Left section**: Position `(-5.5, 2.5, 10)`, Scale `(9, 5, 0.3)`
- **Right section**: Position `(5.5, 2.5, 10)`, Scale `(9, 5, 0.3)`
- This leaves a 2m-wide gap at the centre

---

## Step 3: Add a light

Rooms need at least one light — without it the room is pitch black.

> The scene's default Directional Light is a **scene object** and is **not exported with the bundle**. Add lights as children of your root object.

1. Right-click on the root object → **Light → Directional Light**
2. Set Rotation to `(50, -30, 0)` for a soft angled fill
3. Set **Intensity** to `0.8`

For a more atmospheric look, also add a Point Light:

1. Right-click on the root object → **Light → Point Light**
2. Position: `(0, 4, 0)` — centre, near ceiling
3. Range: `20`, Intensity: `1`

---

## Step 4: Import a door frame asset

The door markers handle logic only — no visual is provided. You need to build or import a door frame to mark the opening.

### Option A — Build one from Cubes (simplest)

Create two tall thin Cubes as door posts and one flat Cube as the lintel:

- **Left post**: Position `(-1.1, 2.5, 10)`, Scale `(0.2, 5, 0.3)`
- **Right post**: Position `(1.1, 2.5, 10)`, Scale `(0.2, 5, 0.3)`
- **Lintel**: Position `(0, 5, 10)`, Scale `(2.4, 0.3, 0.3)`

### Option B — Import from Blender (FBX)

Unity 2018 is **not compatible** with most Unity Asset Store packages (they require Unity 2019+). The recommended way to bring in custom 3D assets is to export from **Blender** as FBX.

**In Blender:**

1. Model or download your door frame mesh
2. **File → Export → FBX (.fbx)**
3. In the export settings:
   - Check **Apply Transform** (under Geometry)
   - **Forward**: `-Z Forward`
   - **Up**: `Y Up`
   - Scale: `1.00`
4. Save the `.fbx` file

**In Unity:**

1. Drag the `.fbx` file from Windows Explorer into the **Project** panel (anywhere under `Assets/`)
2. Unity imports it automatically — a model asset appears
3. Drag the model from the Project panel into the Hierarchy, under your root object
4. Position it at the exit opening

---

## Step 5: Place the spawn marker

1. Right-click on the root object → **Create Empty**
2. Rename it exactly `SpawnHere`
3. Position: `(0, 0, -5)` — away from the door, somewhere in the room

---

## Step 6: Place the exit door marker

1. Right-click on the root object → **Create Empty**
2. Rename it `WhatLockIsNeeded`
3. Position: `(0, 1, 9.5)` — at the centre of the opening
4. Right-click on `WhatLockIsNeeded` → **Create Empty**
5. Rename the child `UnbarredDoor` — this door is always open (no enemies needed)

> Once you add enemies (tutorial 04), replace `UnbarredDoor` with `MonsterLock`.

---

## Step 7: Hierarchy check

```
my-pack_MainRoom
├── Plane (floor)
├── Cube (south wall)
├── Cube (east wall)
├── Cube (west wall)
├── Cube (north wall left)
├── Cube (north wall right)
├── Cube (ceiling)
├── Cube (door post left)
├── Cube (door post right)
├── Cube (door lintel)
├── Directional Light
├── Point Light
├── SpawnHere
└── WhatLockIsNeeded
    └── UnbarredDoor
```

---

## Step 8: Create the Prefab

1. In the **Project** panel, create a folder: right-click → **Create → Folder**, name it `Rooms`
2. Drag your root object from the **Hierarchy** into the `Rooms` folder
3. A blue Prefab file appears — the Hierarchy object turns blue too

---

## Step 9: Assign the Asset Bundle

1. Select the Prefab in the `Rooms` folder
2. At the bottom of the **Inspector**, find the **AssetBundle** section
3. Click the left dropdown (`None`) → **New** → type your bundle name: `my-pack`
4. Leave the right dropdown empty

---

## Step 10: Export

> ⚠️ Do **not** use **File → Build Settings → Build** — that builds a full game and will fail.

1. Top menu → **Build → Asset Bundles (Windows)**
2. Wait a few seconds
3. A `Bundles/` folder appears at the root of the Unity project
4. Find the file named `my-pack` (no extension) — rename it to `my-pack.rooms`

---

## Step 11: Install and test

1. Copy `my-pack.rooms` into:
   ```
   BepInEx\data\fantastic-jam-DKReforged\rooms\my-pack\
   ```
2. Launch VR Dungeon Knight, start a solo run
3. Check `BepInEx\LogOutput.log` for:
   ```
   [RoomLoader] 1 room(s) loaded from my-pack.rooms (pool: NormalRoomStructures)
   ```

> If your room does not appear after several runs it is being selected randomly. Set `TestRoom = my-pack` in the BepInEx config file to force it as the first room.

---

## Common issues

| Problem | Fix |
|---|---|
| "Asset bundle version mismatch" in logs | Wrong Unity version — must be exactly **2018.2.4f1** |
| Room loads but player falls through | Floor Plane is too small or missing |
| Exit does not trigger | `WhatLockIsNeeded` is missing or has no child (`UnbarredDoor` / `MonsterLock`) |
| Nothing in logs from RoomLoader | Bundle filename does not match folder name |

---

## Next

→ [03-improve-room.md](03-improve-room.md) — add textures, better assets, and loot
