How I can stretch texture with GUI.DrawTextureWithTexCoords ?

Could someone explain me, how can I draw GUI Texture partially (with given UV-coords) and make texture stretched (with aspect ration different from it`s original)?

GUI.DrawTexture can stretch textures, but cannot draw a part of it.
GUI.DrawTextureWithTexCoords can accept the UVs, but cannot stretching options.

My case:
I draw animated GUI-elements, and use UVs to draw one frame of spritesheet. It worked fine until I had to animate non-square texture. Besides, the size (and aspect ratio) of the output rect is calculated runtime.

Does someone know any solution?

Thanks in advance :slight_smile:

Using GUI.DrawTextureWithTexCoords() you can draw part of a texture. You need to set correctly coordinate UVs. For example, we should draw only a half of a texture in a certain size. See an example below(write on CSharp):

 public Texture2D myTex = null; //our texture, reference in Inspector
 private Rect myRect; //our UVs coordinate

 void Start() {
  //Initialixation rectangle for half texture;
  myRect = new Rect(0, 0, 0.5f, 0.5f);

 void OnGUI() {
  //Draw our part texture for size, for example, 300x200. It doesn't consider aspect of a texture
  //first element - position, second - texture, third - UVs
  GUI.DrawTextureWithTexCoords(new Rect(20, 20, 300, 200), myTex, myRect);

I hope that it will help you.