- Home /
Aligning a GUI.DrawTexture from the right?
In my game, I have an avatar-like texture, that changes dynamically during the game. My problem is that Rects are aligned from the top-left. I would like to have my image be aligned from the bottom-right.
Here's an image of what I mean:
I'd also settle for centre or top-right, as long as it's right. Is this possible?
I've tried using the GUIStyle, but DrawTexture doesn't except that to begin with. I hope someone can help me out.
-Veliremus
SOLVED
Here's what I came up with after the first answer:
//define screenwidth here for optimal performance var screenwidth = Screen.width; var screenhieght = Screen.height; var myTexture : Texture2D;
function OnGUI() { GUI.DrawTexture (Rect (screenwidth - myTexture.width, screenheight - myTexture.height, myTexture.width, myTexture.height), myTexture, ScaleMode.ScaleToFit); }
Answer by Molix · Apr 19, 2010 at 12:13 PM
You'll just need to modify the coordinates you pass to DrawTexture, e.g. (C#)
public Vector2 myTextureSize = new Vector2( 100, 100 );
void OnGUI() { GUI.DrawTexture( new Rect( Screen.width - myTextureSize.x, Screen.height - myTextureSize.y, myTextureSize.x, myTextureSize.y ), myTexture ); }
Thank you very much, your idea gave me a new idea, which I posted in my original question :).
Your answer
Follow this Question
Related Questions
Procedural Mesh lines with AA 0 Answers
Align texture on object? 3 Answers
Assigning UV Map to model at runtime 0 Answers
Aligning Textures in simple planes 1 Answer
Sprite texture flickering. 2 Answers