I have a C# script in unity(attached to the bottom of the post) and I am itterating through a image pixel by pixel and I am confused on the results I get. There is an extra white block being processed in at the beginning of processing and results in the overall map being thrown off in generation. The image is exactly 50×50 pixels.

A better way would be to put it is as the image below(screenshot from pixel painting app so you can see the pixel grid) starting in the bottom left hand corner going from left to right then up the rows in processing. At the beginning there is an extra white pixel being read. So in the image there are 4 white pixels and then one orange. But from the Console output included below the code below adds an extra white pixel before it sees the orange.

```
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;
using System.IO;
public class LevelGenerator : MonoBehaviour
{
(TitleGroup("Base Settings"))
(Space)
(Header("Ground"))
public GameObject groundTile1;
public GameObject groundTile2;
public GameObject groundTile3;
(Space)
(Header("Parent Game Objects"))
public GameObject groundParent;
public GameObject roadsParent;
public GameObject towersParent;
public GameObject treeParent;
public GameObject groundClutterParent;
public GameObject housesParent;
public GameObject waterParent;
(Space)
(Header("Road"))
public GameObject roadTile1;
public GameObject roadTile2;
public GameObject roadTile3;
(Space)
(Header("Water"))
public GameObject waterTile;
(Space)
(Header("Trees"))
public GameObject tree1;
public GameObject tree2;
public GameObject tree3;
(Space)
(Header("Ground Clutter"))
public GameObject groundClutter1;
public GameObject groundClutter2;
(Space)
(Header("Houses"))
public GameObject house1;
public GameObject house2;
(Space)
(Header("Tower Spot Tile"))
public GameObject towerSpotTile;
(Space)
(Header("Map"))
public Texture2D map;
(Space)
(Header("Debug Log"))
(Header("Basic Details"))
public int width;
public int height;
public string logLocation;
(Header("Sizing Details"))
public GameObject baseCube;
public float baseCubeHeight;
public float baseCubeWidth;
public float baseCubeDepth;
(Button(ButtonSizes.Small))
private void getDimensions()
{
CalculateHeightAndWidth();
}
// Start is called before the first frame update
void Start()
{
CalculateHeightAndWidth();
}
// Update is called once per frame
void Update()
{
}
public void CalculateHeightAndWidth()
{
baseCubeHeight = baseCube.GetComponent<Renderer>().bounds.size.y;
baseCubeWidth = baseCube.GetComponent<Renderer>().bounds.size.x;
baseCubeDepth = baseCube.GetComponent<Renderer>().bounds.size.z;
//Reset class variables to 0
height = 0;
width = 0;
float curDepth;
float curWidth;
Color pixelColor;
GameObject placeThis;
string outputPath = "Assets/Logs/level_generator_log.txt";
StreamWriter writer = new StreamWriter(outputPath, true);
for (int hcount = 0; hcount < map.height; hcount++)
{
for (int wcount = 0; wcount < map.width; wcount++)
{
pixelColor = map.GetPixel(width, height);
writer.WriteLine("/r/n The current pixel (W=" + wcount + " x H=" + hcount +") Color: "+ToHEX(pixelColor)+" - Block Type = "+whichBlockType(ToHEX(pixelColor)));
//Incriment Class Width Counter
width = wcount;
}
//Incriment Class Height Counter
height = hcount;
}
writer.Close();
}
public string whichBlockType(string colorCode)
{
switch (colorCode)
{
//Road
case "000000": //Black
//Debug.Log("road");
return "road";
//break;
//Tower Spots
case "DA0205": //Red
//Debug.Log("tower spot");
return "tower";
//break;
//Water
case "023ADA": //Blue
//Debug.Log("water");
return "water";
//break;
//Ground Clutter
case "02DA37": //Green
return "groundClutter";
case "4D2122": //Brown
//Debug.Log("tree");
return "house";
//break;
//Starting Portal
case "FD8F4D": //Orange
//Debug.Log("start-portal");
return "start-portal";
//break;
//Ground
case "FFFFFF":
//Debug.Log("ground");
return "ground";
//break
default:
return "ERROR: UKNOWN BLOCK TYPE! ERROR 1 - LevelGenerator.cs Line 150";
}
}
public string ToHEX(Color color)
{
string hex = ColorUtility.ToHtmlStringRGB(color);
return hex;
}
```

}

Log

```
The current pixel (W=0 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=1 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=2 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=3 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=4 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=5 x H=0) Color: FD8F4D - Block Type = start-portal
The current pixel (W=6 x H=0) Color: FD8F4D - Block Type = start-portal
The current pixel (W=7 x H=0) Color: FD8F4D - Block Type = start-portal
The current pixel (W=8 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=9 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=10 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=11 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=12 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=13 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=14 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=15 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=16 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=17 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=18 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=19 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=20 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=21 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=22 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=23 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=24 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=25 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=26 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=27 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=28 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=29 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=30 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=31 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=32 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=33 x H=0) Color: DA0205 - Block Type = tower
The current pixel (W=34 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=35 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=36 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=37 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=38 x H=0) Color: DA0205 - Block Type = tower
The current pixel (W=39 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=40 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=41 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=42 x H=0) Color: DA0205 - Block Type = tower
The current pixel (W=43 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=44 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=45 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=46 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=47 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=48 x H=0) Color: DA0205 - Block Type = tower
The current pixel (W=49 x H=0) Color: FFFFFF - Block Type = ground
The current pixel (W=0 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=1 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=2 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=3 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=4 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=5 x H=1) Color: FD8F4D - Block Type = start-portal
The current pixel (W=6 x H=1) Color: FD8F4D - Block Type = start-portal
The current pixel (W=7 x H=1) Color: FD8F4D - Block Type = start-portal
The current pixel (W=8 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=9 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=10 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=11 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=12 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=13 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=14 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=15 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=16 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=17 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=18 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=19 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=20 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=21 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=22 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=23 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=24 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=25 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=26 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=27 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=28 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=29 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=30 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=31 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=32 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=33 x H=1) Color: DA0205 - Block Type = tower
The current pixel (W=34 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=35 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=36 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=37 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=38 x H=1) Color: DA0205 - Block Type = tower
The current pixel (W=39 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=40 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=41 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=42 x H=1) Color: DA0205 - Block Type = tower
The current pixel (W=43 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=44 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=45 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=46 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=47 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=48 x H=1) Color: DA0205 - Block Type = tower
The current pixel (W=49 x H=1) Color: FFFFFF - Block Type = ground
The current pixel (W=0 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=1 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=2 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=3 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=4 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=5 x H=2) Color: 000000 - Block Type = road
The current pixel (W=6 x H=2) Color: 000000 - Block Type = road
The current pixel (W=7 x H=2) Color: 000000 - Block Type = road
The current pixel (W=8 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=9 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=10 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=11 x H=2) Color: 02DA37 - Block Type = groundClutter
The current pixel (W=12 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=13 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=14 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=15 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=16 x H=2) Color: DA0205 - Block Type = tower
The current pixel (W=17 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=18 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=19 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=20 x H=2) Color: DA0205 - Block Type = tower
The current pixel (W=21 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=22 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=23 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=24 x H=2) Color: DA0205 - Block Type = tower
The current pixel (W=25 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=26 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=27 x H=2) Color: DA0205 - Block Type = tower
The current pixel (W=28 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=29 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=30 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=31 x H=2) Color: DA0205 - Block Type = tower
The current pixel (W=32 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=33 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=34 x H=2) Color: 000000 - Block Type = road
The current pixel (W=35 x H=2) Color: 000000 - Block Type = road
The current pixel (W=36 x H=2) Color: 000000 - Block Type = road
The current pixel (W=37 x H=2) Color: 000000 - Block Type = road
The current pixel (W=38 x H=2) Color: 000000 - Block Type = road
The current pixel (W=39 x H=2) Color: 000000 - Block Type = road
The current pixel (W=40 x H=2) Color: 000000 - Block Type = road
The current pixel (W=41 x H=2) Color: 000000 - Block Type = road
The current pixel (W=42 x H=2) Color: 000000 - Block Type = road
The current pixel (W=43 x H=2) Color: 000000 - Block Type = road
The current pixel (W=44 x H=2) Color: 000000 - Block Type = road
The current pixel (W=45 x H=2) Color: 000000 - Block Type = road
The current pixel (W=46 x H=2) Color: 000000 - Block Type = road
The current pixel (W=47 x H=2) Color: 000000 - Block Type = road
The current pixel (W=48 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=49 x H=2) Color: FFFFFF - Block Type = ground
The current pixel (W=0 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=1 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=2 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=3 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=4 x H=3) Color: DA0205 - Block Type = tower
The current pixel (W=5 x H=3) Color: 000000 - Block Type = road
The current pixel (W=6 x H=3) Color: 000000 - Block Type = road
The current pixel (W=7 x H=3) Color: 000000 - Block Type = road
The current pixel (W=8 x H=3) Color: DA0205 - Block Type = tower
The current pixel (W=9 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=10 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=11 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=12 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=13 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=14 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=15 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=16 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=17 x H=3) Color: 000000 - Block Type = road
The current pixel (W=18 x H=3) Color: 000000 - Block Type = road
The current pixel (W=19 x H=3) Color: 000000 - Block Type = road
The current pixel (W=20 x H=3) Color: 000000 - Block Type = road
The current pixel (W=21 x H=3) Color: 000000 - Block Type = road
The current pixel (W=22 x H=3) Color: 000000 - Block Type = road
The current pixel (W=23 x H=3) Color: 000000 - Block Type = road
The current pixel (W=24 x H=3) Color: 000000 - Block Type = road
The current pixel (W=25 x H=3) Color: 000000 - Block Type = road
The current pixel (W=26 x H=3) Color: 000000 - Block Type = road
The current pixel (W=27 x H=3) Color: 000000 - Block Type = road
The current pixel (W=28 x H=3) Color: 000000 - Block Type = road
The current pixel (W=29 x H=3) Color: 000000 - Block Type = road
The current pixel (W=30 x H=3) Color: 000000 - Block Type = road
The current pixel (W=31 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=32 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=33 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=34 x H=3) Color: 000000 - Block Type = road
The current pixel (W=35 x H=3) Color: 000000 - Block Type = road
The current pixel (W=36 x H=3) Color: 000000 - Block Type = road
The current pixel (W=37 x H=3) Color: 000000 - Block Type = road
The current pixel (W=38 x H=3) Color: 000000 - Block Type = road
The current pixel (W=39 x H=3) Color: 000000 - Block Type = road
The current pixel (W=40 x H=3) Color: 000000 - Block Type = road
The current pixel (W=41 x H=3) Color: 000000 - Block Type = road
The current pixel (W=42 x H=3) Color: 000000 - Block Type = road
The current pixel (W=43 x H=3) Color: 000000 - Block Type = road
The current pixel (W=44 x H=3) Color: 000000 - Block Type = road
The current pixel (W=45 x H=3) Color: 000000 - Block Type = road
The current pixel (W=46 x H=3) Color: 000000 - Block Type = road
The current pixel (W=47 x H=3) Color: 000000 - Block Type = road
The current pixel (W=48 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=49 x H=3) Color: FFFFFF - Block Type = ground
The current pixel (W=0 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=1 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=2 x H=4) Color: 02DA37 - Block Type = groundClutter
The current pixel (W=3 x H=4) Color: 4D2122 - Block Type = house
The current pixel (W=4 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=5 x H=4) Color: 000000 - Block Type = road
The current pixel (W=6 x H=4) Color: 000000 - Block Type = road
The current pixel (W=7 x H=4) Color: 000000 - Block Type = road
The current pixel (W=8 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=9 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=10 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=11 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=12 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=13 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=14 x H=4) Color: 02DA37 - Block Type = groundClutter
The current pixel (W=15 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=16 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=17 x H=4) Color: 000000 - Block Type = road
The current pixel (W=18 x H=4) Color: 000000 - Block Type = road
The current pixel (W=19 x H=4) Color: 000000 - Block Type = road
The current pixel (W=20 x H=4) Color: 000000 - Block Type = road
The current pixel (W=21 x H=4) Color: 000000 - Block Type = road
The current pixel (W=22 x H=4) Color: 000000 - Block Type = road
The current pixel (W=23 x H=4) Color: 000000 - Block Type = road
The current pixel (W=24 x H=4) Color: 000000 - Block Type = road
The current pixel (W=25 x H=4) Color: 000000 - Block Type = road
The current pixel (W=26 x H=4) Color: 000000 - Block Type = road
The current pixel (W=27 x H=4) Color: 000000 - Block Type = road
The current pixel (W=28 x H=4) Color: 000000 - Block Type = road
The current pixel (W=29 x H=4) Color: 000000 - Block Type = road
The current pixel (W=30 x H=4) Color: 000000 - Block Type = road
The current pixel (W=31 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=32 x H=4) Color: 02DA37 - Block Type = groundClutter
The current pixel (W=33 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=34 x H=4) Color: 000000 - Block Type = road
The current pixel (W=35 x H=4) Color: 000000 - Block Type = road
The current pixel (W=36 x H=4) Color: 000000 - Block Type = road
The current pixel (W=37 x H=4) Color: 000000 - Block Type = road
The current pixel (W=38 x H=4) Color: 000000 - Block Type = road
The current pixel (W=39 x H=4) Color: 000000 - Block Type = road
The current pixel (W=40 x H=4) Color: 000000 - Block Type = road
The current pixel (W=41 x H=4) Color: 000000 - Block Type = road
The current pixel (W=42 x H=4) Color: 000000 - Block Type = road
The current pixel (W=43 x H=4) Color: 000000 - Block Type = road
The current pixel (W=44 x H=4) Color: 000000 - Block Type = road
The current pixel (W=45 x H=4) Color: 000000 - Block Type = road
The current pixel (W=46 x H=4) Color: 000000 - Block Type = road
The current pixel (W=47 x H=4) Color: 000000 - Block Type = road
The current pixel (W=48 x H=4) Color: FFFFFF - Block Type = ground
The current pixel (W=49 x H=4) Color: FFFFFF - Block Type = ground
```