Maze Generator – Expandable Procedural Tile system for Unity



This is my attempt at a maze generator in unity, it should be viable for any tile-based game. It takes tiles (corridors or rooms) of a fixed size and builds a customisable path from start room to end room, and then adds similar paths at random points along the chain.

The paths can be winding and diverse but will never wrap so long as there are no L-shaped tiles. The operation runs in a coroutine so it can make for quite a dramatic live-build effect as seen in the video. The script is easily expandable and allows for more than just simple floor tiles. For example, the original project included walls and doors but theoretically any numbers of additional object could be built into the enemy (enemy spawn points, upgrades, coins, etc).

Full script below (Creative Commons 4.0)




This is the main script. Unlike in the video tutorial, the Room/Corridor scripts are not necessary, only that the tiles have the Tile class attached (shown at the bottom of the page). Even that could be fixed relatively easily by simply replacing any Tile reference with GameObject.

This is the tile script. The code itself is not actually necessary but may help with placing the exits correctly.

I also made an editor script that adds a button to remake the maze. That way you don’t have to reload the entire instance.

Maze Generator Cover Image

I hope this helps anyone trying to make a maze game or any sort of room-based game.


If you liked this rambling, shoddy tutorial then be sure to check out my Dialogue System Tutorial!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.