- Home /
How to not scale my Texture?
I am creating a bar of sorts, and I just crop the image Rect to exclude a partition of the source rectangle but it seems you cant do this in Unity without some kind of work around. XNA had a really nice way of just cropping the image by use of a source rectangle, which would be the exact rectangle of which pixels of the sprite you really wanted to show.
My display code is as follows:
GUI.DrawTexture(new Rect(playerPosition.x, playerPosition.y,
(_playerAttributes.Stamina/_playerAttributes.MaxStamina) * gui_StaminaBar_Overlay.width, gui_StaminaBar_Overlay.height),
gui_StaminaBar_Overlay);
Answer by WillNode · Dec 23, 2014 at 12:44 PM
use a function called DrawTextureWithTexCoords to draw image with cropping an image.
Rect imgDest = new Rect(playerPosition.x, playerPosition.y, (_playerAttributes.Stamina/_playerAttributes.MaxStamina) * gui_StaminaBar_Overlay.width, gui_StaminaBar_Overlay.height); //Coordinate on Screen
Rect imgSource = new Rect (0,0,(_playerAttributes.Stamina/_playerAttributes.MaxStamina) * gui_StaminaBar_Overlay.width, gui_StaminaBar_Overlay.height); //Coordinate to Crop Image
GUI.DrawTextureWithTexCoords(imgDest, gui_StaminaBar_Overlay,imgSource);
Thanks so much, I had just figured it out right before you replied.
Life safer! :D
Your answer
Follow this Question
Related Questions
Unity camera Cropping 2 Answers
Rect.ymax wrong? 1 Answer
Android UI White Rectangles on Inputbox Select 1 Answer
Crop face and made it texture for 3d model 0 Answers
Random position in rectangle, but not in a camera view 1 Answer