TL;DR,
I wasn't resetting my X correctly and incrementing my Z in the right order.
Hey all,
Using Map and Nav, I'm created a 30x30 grid of nodes, each with a prefab child, the properties and material of which I can change at runtime to make a Procedurally generated map, albeit a small one.
I've got a for loop for current rooms < max rooms.
In each iteration, the basic loops is as follows.
Z<=Zi (Z being the starting Z,and Zi being the height of the room.)
Under that another loop
X<=X1 (same relationship but for width.
I randomize the values a little, but each room starts with X and Z at the same value.
With Z and X at 0, I run them through another for loop which iterates through an array of nodes(yeah array maker and find all by tag), and checking to see if both the Z and X values from my loops, match the Z and X position of the node at the current index.
If so, I tell the node to get it's child and change it's material from wall to floor.
I then increment X and return to the step in the for loop where X<=X1(Width) and continue to compare my Z(so far unchanged) and X values. When I find a tile that matches those values, I repeat the process.
Once X has reach X!, I know I've drawn the entire width of the room, so I increment Z, which if it is still <= Z1(height) I start to iterate through the X values again, comparing the Z and X values to each index of an array of nodes and changing tiles appropriately.
The problem I am runnig into, is that for each room, the Z value is drawn once, all the X values are iterated through and drawn, but when I increment Z, It jumps directly to the increment number of rooms step and I end up with 5 X wide lines at 5 different Z heights.
However, with the four variables I have Z, Z height, X and X Width, I should be able to draw a rectangle, no?
For Z<= Z1
For X<= X1
Run Z and X values through a for loop looking for a match.
If match, alter prefab tile child of node.
Increment X
Loop Back to For X<=X1
When X=X1
Increment Z
Z For Loop
X for Loop
Continue to loop through all nodes looking for a match and changing that tile at those coords.
When Z > Z1
Increment Number of Rooms
For Number of rooms <= Max Rooms
Randomize room dimensions
back to Z for Loop.
I'm not clear why this doesn't work.
Any thoughts?
Thanks,
-Luke