- Home /
Texture on center bottom of screen
Hi,
I have a texture that I want to show on the center bottom of the screen. I know how to get it to the center of the screen, but how do I get it to the bottom?
var show : boolean;
var inventory : Texture2D;
function OnGUI () {
GUI.depth = 100;
if(show){
//show inventory bar
GUI.DrawTexture(new Rect(Screen.width / 2, Screen.height / 2,248,46), inventory);
}
}
Answer by Griffo · Sep 14, 2012 at 11:13 AM
GUI.DrawTexture(new Rect(Screen.width / 2, Screen.height - Screen.height,248,46), inventory);
This script puts the texture completely at top center of the screen.
I got it to work with the script above. Screen.height - 56. Thanks!
Answer by Griffo · Sep 14, 2012 at 11:10 AM
var show : boolean;
var inventory : Texture2D;
private var gui : GUITexture; //Reference to the GUITexture component of this gameObject
function Awake() {
gui = GetComponent("GUITexture"); //Gather the reference for the GUITexture component
gui.texture = inventory;
gui.pixelInset.x = Screen.width / 2;
gui.pixelInset.y = Screen.height - Screen.height;
}
I tried this script, but the texture doesn't appear anywhere.
This should work I use it and it puts a GUI button bottom centre of my screen
Answer by instruct9r · Sep 14, 2012 at 12:31 PM
Hello. I think this might do the job:
var show : boolean;
var inventory : Texture2D;
private var inventoryW : float;
private var inventoryH : float;
// Store the inventory W / H in these 2 vars
function Start()
{
inventoryW = inventory.width / 2;
inventoryH = inventory.height;
}
function OnGUI () {
GUI.depth = 100;
if(show){
//show inventory bar
GUI.DrawTexture(Rect(Screen.width / 2 - inventoryW, Screen.height - inventoryH, 248,46), inventory);
}
}
I think that shoud work...
You simply have to take the Screen.height and since it start from TOP to BOTTOM if you'r screen.height is 600 then 600 will be at the bottom line. So you remove 248 from 600 and you'r texture will be exactly above the bottom line.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
GUI.Drawtexture Overlaping Other GUI.Drawtexture. 1 Answer
How to change rect size? 2 Answers