Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity 180 rotation for a Texture2D, or maybe flip both

I could use just a little help. I am loading a png into a Texture2D, and have managed to flip it over the y axis using the following script I found. I need to flip it over the x axis now. I know a small modification should do it, but I have not managed to get the results I want.

    Texture2D FlipTexture(Texture2D original){
    Texture2D flipped = new Texture2D(original.width,original.height);

    int xN = original.width;
    int yN = original.height;

    for(int i=0;i<xN;i++){
        for(int j=0;j<yN;j++){
            flipped.SetPixel(xN-i-1, j, original.GetPixel(i,j));
        }
    }

    flipped.Apply();

    return flipped;
}
like image 737
OT2O Avatar asked Dec 15 '22 07:12

OT2O


1 Answers

say "pix" is a png,

Texture2D photo;
Color[] pix = photo.GetPixels(startAcross,0, 256,256);
// (256 is just an example size)

this ENTIRELY ROTATES a png 180 degrees

System.Array.Reverse(pix, 0, pix.Length);

this mirrors a PNG just around the upright axis

        for(int row=0;row<256;++row)
            System.Array.Reverse(pix, row*256, 256);
like image 127
Fattie Avatar answered Jan 05 '23 01:01

Fattie