Save a picture of a maze
I have a maze generator, and I want to be able to save the mazes it makes as .png files. My generator makes mazes with squares, and in the save files, I want each square on the maze to be 1 pixel. Does anyone know how to do this? Here is an example generated maze:
Answer by agray427 · Jan 15, 2018 at 08:29 PM
Say you create a maze that is 128 squares by 128 squares. You can then create a new Texture2D(128, 128). Then, you iterate over your maze determining what each square is at position (x, y). Then you determine what color you want that type of square to be represented as. Then, you say texture.SetPixel(x, y, color); After you get done iterating over everything, you need to convert it to a byte array by saying texture.EncodeToPNG(); Lastly, you need to save the file by saying File.WriteAllBytes(, );.
Your answer
Follow this Question
Related Questions
Windows Store build errors inside Unity 1 Answer
.Net 3.5 to 4.6 Upgrade --> messed up scales at Collada Models 0 Answers
Lighting in a maze game 0 Answers
System.Net.WebRequest on Xbox One? 0 Answers
Unity .NET 4.6 Socket Exception 2 Answers