Maze tile deployment help (Novice)

I’m trying make a small grid-based maze (With expanded functionality later). I want it to be 20 tiles wide and 12 tiles tall, using 60px x 60px tiles (A 1280x720 20x12 grid all-in-all).

My question is this: How can I efficiently place all of the tiles such that they can be easily set up and arranged? Being completely green, the only way I can see is to create 240 objects, which seems less than ideal. I want white tiles to be traversable and black tiles to block movement.

Attached is an example of the framework I’d like to set up (Threw it together in excel):


(It has a trivial solution and no surprises because I want to master the “maze” concept before I tackle additional features)

I apologize if my question is exceedingly n00bish - this is my first crack at developing in Unity.

Thanks for any help.

Really, there are any number of ways you might approach this, including (as you mentioned) creating 320 individual objects and placing them by hand - though that probably shouldn’t be near the top of the list… :wink:

One solution might be something like:

  • Create your “map” in a simple text file with each character representing a “tile” in your grid. So, you’d have a text file containing 12 lines of text and each line would contain 20 characters. While you could use anything, you might decide that a “0” is a black square and a “1” is a white square.
  • Create a simple script that accepts 2 Unity “prefabs”. One of the white square and one of the black square. This script would then read the text file-based level and clone and position each square based on the contents of the text file.

That way, to change the map, you’d just change the contents of the text file. Since you’re supplying the squares as prefabs to the script, they could already be “wired” with the necessary components to assist in navigation. For instance, the square that’s not navigable could already have the necessary physics components on it to prevent your “character” from crossing over it.

Again, there are many ways you can do this - with the above being only one very basic possibility…

Jeff

Thanks a ton for the reply. I’ll give your suggestion a try and see where it leads me. (Now I just have to figure out how to do it :P)

I appreciate the help! :slight_smile:

If you decide to place the tiles 1 by 1 in your scene then vertex snapping will be your best friend.

http://imakeinternet.com/unity-2d-tips-vertex-snapping-level-building/