• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by derrtyones · Sep 14, 2012 at 10:55 AM · javascriptguidrawtexture

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);
     }
 }
Comment

People who like this

0 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Griffo · Sep 14, 2012 at 11:13 AM

 GUI.DrawTexture(new Rect(Screen.width / 2, Screen.height - Screen.height,248,46), inventory);
Comment
derrtyones

People who like this

1 Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image derrtyones · Sep 14, 2012 at 11:15 AM 0
Share

This script puts the texture completely at top center of the screen.

avatar image derrtyones · Sep 14, 2012 at 11:39 AM 0
Share

I got it to work with the script above. Screen.height - 56. Thanks!

avatar image Griffo · Sep 14, 2012 at 11:42 AM 0
Share

Glad I could help ..

avatar image

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 t$$anonymous$$s 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;
     }
Comment

People who like this

0 Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image derrtyones · Sep 14, 2012 at 11:16 AM 0
Share

I tried this script, but the texture doesn't appear anywhere.

avatar image Griffo · Sep 14, 2012 at 11:25 AM 0
Share

This should work I use it and it puts a GUI button bottom centre of my screen

avatar image

Answer by instruct9r · Sep 14, 2012 at 12:31 PM

Hello. I t$$anonymous$$nk t$$anonymous$$s 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 t$$anonymous$$nk 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.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Setting Scroll View Width GUILayout 1 Answer

GUI.Drawtexture Overlaping Other GUI.Drawtexture. 1 Answer

How to change rect size? 2 Answers

[Closed]GUI.DrawTexture inside GUI.DrawTexture 1 Answer

Fade between textures in the same script? 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges