- Home /
GUI Texture on bottom left/right corners
Hello everyone. I want to make a 2D texture in the bottom right of the screen. But if I adjust it within the inspector, the position of the 2D Gui Texture can be different according to the resolutions. So I know that it can be arranged with code and suitable for every resolution. I have a code that makes a GUI label on the right bottom but I couldn't figure out how to make it for drawing a texture.
GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80),"something: ");
this is what I use for creating a text in bottom right corner. I want the same thing for the texture. Can someone lead me to the right way for doing this ? Thanks :)
Answer by gregzo · Apr 13, 2012 at 04:42 PM
Careful! GUITextures pixelInset properties have their origin at the bottom left of the screen. Just adapt the code you have for GUI.Label accordingly, using GUITexture.pixelInset.x and y. I hope I'm clear!
just at a guess , I think @T-Pr is after something like this :
var myBoxTexture : Texture2D;
function OnGUI()
{
GUI.Box (Rect(Screen.width - 200,Screen.height-35,200,80), myBoxTexture);
GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80), "something: ");
}
drag-and-drop your image into the Inspector where it says 'myBoxTexture' =]
well that's almost what I wanted, thanks for hat :). But is there a way of doing it without drawing a box ? Or making the box invisible, because the size of the texture is adjusted according to the size of the box.
I havn't done anything like that myself (am a noob really), gregzo or someone can probably answer that. All I can suggest is have a look at the Unity Scripting Reference and hopefully you shall find a method there that you want.
http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTexture.html
http://unity3d.com/support/documentation/ScriptReference/GUI.DrawTextureWithTexCoords.html
http://unity3d.com/support/documentation/ScriptReference/GUI.html
GUITexture is what you're after. In the import settings of your image, select GUI, then in the scene, create GUITexture. Drag and drop your image, reset the transform's position, pixelInset properties will be correct! @alucardj I'm just a noob+, ;)
probably a bit late =] , but I just learned how to do this :
// Draws a texture in the left corner of the screen.
// The texture is drawn in a window 60x60 pixels.
// The source texture is given an aspect ratio of 10x1
// and scaled to fit in the 60x60 rectangle. Because
// the aspect ratio is preserved, the texture will fit
// inside a 60x10 pixel area of the screen rectangle.
var aTexture : Texture;
function OnGUI()
{
// check there is a texture to use
if(!aTexture){
Debug.LogError("Assign a Texture in the inspector.");
return;
}
GUI.DrawTexture(Rect(10,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 0); // aspect ratio is 0 , true image scale displayed
GUI.DrawTexture(Rect(150,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, false, 0.0); // no alphablend (no transparency)
GUI.DrawTexture(Rect(80,10,60,60), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 10.0); // apect of image is changed to ( 60 : 6 ), image is centred to the Rect
GUI.DrawTexture(Rect(10,70,90,90), aTexture, Scale$$anonymous$$ode.ScaleToFit, true, 0); // image is scaled to the size of the Rect given
}
Answer by Malikoguzghost · Jun 03, 2014 at 07:57 AM
maybe you can do it by
function OnGUI() { GUI.backgroundcolor = Color.clear; GUI.Box (Rect(Screen.width - 200,Screen.height-35,200,80), myBoxTexture); GUI.Label (Rect(Screen.width - 200,Screen.height-35,200,80), "something: "); }
:)
Answer by Tranoze · Jan 10, 2018 at 10:11 AM
Use GUIStyle and change it alignment.
guiStyle = new GUIStyle(GUI.skin.label);
guiStyle.font = myFont;
guiStyle.fontSize = 48; //change the font size
guiStyle.normal.textColor = Color.white;
guiStyle.alignment = TextAnchor.LowerRight;
GUI.Label(Rect, "Text", guiStyle);
Your answer
Follow this Question
Related Questions
GUITexture Button? 1 Answer
rotating GUI texture by angle 2 Answers
Sprites and minmizing memory usage 1 Answer
How to place/add a HD image/picture in background of my game? 0 Answers
GUILayer hit doesn't work. Any help? 0 Answers