Unity3D: Flipping a Texture

So today, we were trying to horizontally flip a texture to be used within GUI. There is no option to flip a texture via the inspector so we had to do this through our script.

Here’s the little function we used for this, it’s in unityscript but can very easily be converted to C# by just changing how variables are declared. This can also be adjusted to flip things vertically.

function FlipTexture(orig:Texture2D):Texture2D {
var flip:Texture2D = new Texture2D(orig.width,orig.height);
var xN:int = orig.width;
var yN:int = orig.height;

for(var i:int=0; i < xN; i++) {
for(var j:int=0; j < yN; j++) {
flip.SetPixel(xN-i-1, j, orig.GetPixel(i,j));
}
}

flip.Apply();
return flip;
}