#What am i doing wrong with this texture2d?

1 messages · Page 1 of 1 (latest)

fair socket
#
    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?

#

Dont mind the t-split, its wrong for another reason

bright hollow
#

I do not know the nature of your issue (probably something simple that can be patch; Use Debug.Log to find out the origin of it), however I really question the reason why you use a full texture to define your puzzle.

little stirrup
#

don’t crosspost to different channels

fair socket
bright hollow
#

Also, the way you coded the whole things is kinda hard to read and reflect.

#

Are you aware of the usage of class and object ?

fair socket
#

Yes, this is really more of a first draft!

#

But if its too unreadable, ill tinker with it some more myself. Will get it right at some point

#

Thanks for the assist tho

bright hollow
#

Still, the usage of Debug.Log or break point is your best way to identify the issue.

#

There is too much code to quickly analyze it by doing the Algorithm Trace. It would take more time that I am willing to use.

fair socket
#

Thats completly fair. Im very unfamilair with unity tooling, so i usually do it component based, but i will look into it!

bright hollow
#

I strongly suggest that you make a tool in Unity instead of relying on texture. It could be as simple as showing your designer how the Unity Grid/Snap works.