Seeding the dungeon

We can set a seed value for any dungeon to recreate that dungeon. There is a simple way to test this as well. In the DungeonManager.cs file, add the line Random.seed = 1; to the top of the definition of the StartDungeon function.

Now return to the Unity Editor and play the game. Enter a dungeon and take a screenshot of the overview. Then, end the game and play again. Enter a dungeon and compare its overview to that of the screenshot. You will see that they have the exact same shape.

This is how we can destroy an entire randomly generated dungeon, yet return to it at a later time. You can adapt this line of code for situations such as having a player return to a dungeon to complete a task. For now, you can comment this line out ...

Get Procedural Content Generation for Unity Game Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.