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 daviddickball · Nov 24, 2014 at 09:05 AM · rectalignmentcss

How to align a Rect() to the bottom right of the screen

I'm trying to create a rect of text at the bottom right of the screen. Maybe because I'm a web developer, where stuff like this is easy I'm searching for a more sensble way. Surely there's a way to do this relative to the bottom right corner? In CSS it would be: position:absolute; bottom:10px; right:10px; - easy right? But in Unity I assume the way I have to do it is calculate the height of the screen, minus the box's height, same with the screenwidth minus the box's width. Is that really the best way?

I know doing these calculations won't take me long, but I just wondered if there was a nicer way, like css' position:absolute?

And is there a way to place the text inside the rect, so that it will always adapt to the width of the Rect, or do I have to do the same calculation and have it floating above?

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
Best Answer

Answer by fafase · Nov 24, 2014 at 09:12 AM

  Rect rect = new Rect(Screen.width - width, Screen.height - height, width, height);

But depending what you are using it will be different, for instance using a GUITexture is not the same.

You would have to position the GUITexture based on the normalized screen which has a different coordinate system:

 guitexture.transform.position = new Vector3 (1,0,0);

this will put it in the bottom right but it won't show (Make sure your scale is (0,0,0)).

 Rect rect = new Rect(-width, 0, width, height);
 guiTexture.pixelInset = rect;

or you can leave it at position (0,0,0) ans use something like the first example.

Using a GUIText, the you have the CSS style or alignment bottom right.

So as you see it will depend on what you are after.

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

Follow this Question

Answers Answers and Comments

26 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

In a ScrollRect and a vertical layout group, how do I set child alignment to the left ? 0 Answers

GUI Overlay Display 0 Answers

Positioning Prefabs in exact positions 1 Answer

Apply torque to align rigidbody to a specific angle in 3D 2 Answers

Align object rotation to set positions. 0 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