void Start()
{
int xsections = puzzleMap.width / 3;
if(xsections % 2 != 0) xsections -= 1;
xsections /= 2;
int startedDigitX = 3 * -xsections;
int endDigitX = 3 * xsections;
int zsections = puzzleMap.height / 3;
if(zsections % 2 != 0) zsections -= 1;
zsections /= 2;
int startedDigitZ = 3 * -zsections;
int endDigitZ = 3 * zsections;
for(int x = startedDigitX; x <= endDigitX; x += 3){
for(int z = startedDigitZ; z <= endDigitZ; z += 3){
List<Color> colors = new();
for(int xCollection = x + 6; xCollection < x + 9; xCollection++){
for(int zCollection = z + 6; zCollection < z + 9; zCollection++){
colors.Add(puzzleMap.GetPixel(xCollection, zCollection));
}
}
GeneratePixel(x, z, colors, puzzleMap.width, puzzleMap.height);
}
}
}
void GeneratePixel(int x, int z, List<Color> pixels, float width, float height){
GameObject obj = Instantiate(PickPrefab(pixels), transform);
obj.transform.localPosition = new Vector3(0, z / height, x / width);
obj.transform.localScale = new Vector3(1, 1 / (width / 3), 1 / (height / 3));
obj.transform.Rotate(Rotatation(pixels), 0, 0);
}
Hi! Maybe im doing something wrong, and i am far from optimizing this script, but i have a small bug i cant seem to understand. This is in Unity, so its using Monobehaviour. I am reading a texture2D that scans all pixels and for each 3x3 grid it spawns in a related object. There is more code but it is unrelated. The problem is that the picture basicily get flipped, causing it to swap the left lane with the right line, the second left lane with the second right lane and the middle lane is unaffected. Images for results. Can anyone explain what i am missing?