Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by PirateMonkey · Jul 25, 2014 at 12:09 AM · screendrawtexturescreen.width

GUI.Draw Texture Positioning

Hey,

So this might be a stupid question but I am somewhat new to Unity and find this confusing. I am currently making a game that uses a health bar and speed boost bar. I have been drawing them as rectangles on the screen using GUI.DrawTexture(xPosition, yPosition, etc...)

Where xPosition = Screen.width/2;

I would therefore expect the rectangle to be located in the middle of the screen (or just off since it moves from the bottom left corner), but instead it pops up maybe 1/4 way from the left. Why is it doing this?

I suspect it has something to do with screen space vs world space, but don't know enough about it. Any insight would be appreciated!

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Stormizin · Jul 25, 2014 at 12:09 AM

The question is, if your texture has, 220px of width and u put screen.width/2 your texture will be positioned from the extreme left corner in the givin (screen.with/2), so you need just do this: Screen.width/2 - 220, and bang! you got it in the middle.

Comment
Add comment · 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 PirateMonkey · Jul 25, 2014 at 12:29 AM 0
Share

But if I subtract, wouldn't that push the bar even further left? Here is a picture for reference: alt text

screen shot 2014-07-24 at 6.23.23 pm.png (56.4 kB)
avatar image PirateMonkey · Jul 25, 2014 at 12:31 AM 0
Share

Also, the code I am using for the boost bar (blue bar in the top left):

 var boostPercent : float;
 var xPos : float = (Screen.width / 2);
 var yPos : float = 30;
 var backgroundWidthBoost : float = Screen.width / 6;
 var boostWidth : float;
 var height : float = backgroundWidthBoost/15;
 var boostRemainingBehindTexture : Texture;
 var boostRemainingTexture : Texture;
 
 function OnGUI()
 {
 
 boostPercent = GameObject.Find("Suber").GetComponent(SubControl).boostTimer / GameObject.Find("Suber").GetComponent(SubControl).boostTime;
 boostWidth = (boostPercent * backgroundWidthBoost * -1) + backgroundWidthBoost;
 
 //Draws a rectangle of x,y position, rec width and height, and wrapped in a specified texture
 GUI.DrawTexture(Rect(xPos,yPos,backgroundWidthBoost,height), boostRemainingBehindTexture, Scale$$anonymous$$ode.StretchToFill, true, 1.0f);
 GUI.DrawTexture(Rect(xPos,yPos,boostWidth,height), boostRemainingTexture, Scale$$anonymous$$ode.StretchToFill, true, 1.0f);
 
 }
avatar image Stormizin · Jul 25, 2014 at 12:37 AM 0
Share

Did you need it to left? so subtract or right just use +

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.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Keeping screen width and scaling screen height for different screen resolutions 2 Answers

Make area adapt to screen size 1 Answer

Can't work with screen.width / height 3 Answers

Can you tell unity to resize the Game window by a button press? 2 Answers

Getting Device Screen Height and width in inches 2 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