How can I resize a texture in GUI and display it centered?


I need to resize a texture and center it on the new rectangle. I’m using the GUI.DrawTextureWithTexCoords to try to achieve this but without success. Can anyone explain me if there is another way to do it?

I can see the texture is being resized but for more that I change the parameters I cannot center the image on the rectangle.

GUI.DrawTextureWithTexCoords(new Rect(140, 10, 120, 120), texture, new Rect(0, 0, -0.50f, -0.50f), true);

Thanks in advance.

Try just using a Label instead. You can specify a Texture to use on the Label, and I believe it stretches to fill the whole Label.

Hello Moohasha, thanks for answering. I’ve tried to use the label instead, but how do I specify the scale for the texture? I even tried to make the label larger because yes it stretches, and then apply a GUIStyle and edit margins, borders or padding, but as soon as I’m able to make the label smaller again, the texture stretches along.
I need a label 120px x 120px and the texture will have to appear with the double of the size, centered. Do you think is possible to achieve this? I know I could just enlarge it outside unity, but I need to use the texture in both sizes along game.