- Home /
How to place a Gui Texture correctly?
Hi, i am trying to place a gui texture according to screen resolution.I would place the gui texture using a zero inset in both x and y and just position it using the transform tools, so in this way it would always be positioned at the same place regarding for different screen sizes.As well i am scaling my gui texture to fit to the resolution without streching it.I would do all of these if there was an existing gui texture BUT to you gui utility rotate around pivot, as the documentation says this code will only work for a new gui texture that has drawn.So i use GUI.DrawTexture to draw my texture on screen but cannot find a way how to scale and position it regarding to screen size? If i would do this for an existing gui texture i know how to do it but how can i do it for a new created one?
Answer by aldonaletto · Dec 28, 2013 at 12:00 AM
Don't confuse GUITexture with the GUI system: GUITexture (and GUIText) are scene objects (although transform properties work differently than 3D world objects), while elements of the GUI system are drawn on the fly in OnGUI. If you're using the GUI system, a simple way to adjust GUI items to different resolutions is to scale the GUI matrix (take a look at this answer for more details). If you don't want to scale all GUI items, however, you can scale and/or re-position the rect passed to GUI.DrawTexture. If you want to know the texture size, get its width and height properties:
public var texture: Texture2D; // the texture you want to draw
public var leftPos: float; // left coordinate
public var topPos: float; // top coordinate (0 = top of screen)
function OnGUI(){
var r: Rect = Rect(leftPos, topPos, texture.width, texture.height);
GUI.DrawTexture(r, texture);
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613125002im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to position elements on scene 0 Answers
GUI position not updated on build & run 0 Answers
change bar position 1 Answer
How to use transform.position? 2 Answers