- Home /
[Help]How can I make my maze makes steps as it generate ?
So i just made a simple Maze generator and it works well however It generates the whole maze eventually , what I want to do is to make the maze generates from scratch till it finishes . any ideas ? Here's the code https://pastebin.com/g0Q057KE https://pastebin.com/raNvv4pR
Answer by Defetysta · Nov 29, 2018 at 12:43 PM
I think you could swap the DrawCells() call from Update into a coroutine, it should fix the problem
It may go something along those lines:
private IEnumerator DrawCells(){
Color CellColor = Color.white;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
DrawTopWall (i,j,CellColor);
DrawBottomWall (i, j,CellColor);
DrawLeftWall (i, j,CellColor);
DrawRightWall (i, j,CellColor);
yield return new WaitForEndOfFrame;
}
}
}
For optimization, you could do something like this:
private WaitForEndOfFrame waitForEndOfFrame;
private void Start()
{
waitForEndOfFrame = new WaitForEndOfFrame();
}
// this lets you avoid calling "new WaitForEndOfFrame" each frame, which //can save some computing power
private IEnumerator DrawCells(){
Color CellColor = Color.white;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
DrawTopWall (i,j,CellColor);
DrawBottomWall (i, j,CellColor);
DrawLeftWall (i, j,CellColor);
DrawRightWall (i, j,CellColor);
yield return waitForEndOfFrame;
}
}
}
I think this should work.
Answer by MolhamM · May 30, 2019 at 12:15 AM
Although I solved it with much idiotic solution , I stored all the data i want to visualize in list of struct (contains x,y,direction) and called it in update to make it each time and delete the value that I had drawn , but this one seems much better , Thanks !
Your answer
Follow this Question
Related Questions
Generating 2D collisions for maze 0 Answers
Fill in the small empty gaps (Maze Generator) 1 Answer
Procedural Random Walk Dungeon Generator? 2 Answers
Block based map generator 5 Answers