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 PuneetK · Sep 19, 2013 at 06:18 PM · gui-problem

Adjust GUI according to letterboxed Camera position?

Im currently working on a game which I have forced the camera to be in the 9:15 aspect ratio, for certain reasons. (It letterboxes the sides of the screen)

But all my GUI elements are placed relatively according to Screen.width and Screen.height

So what happens is, even though I've forced the actual gameplay into 9:15 (by adjusting camera distance, scale, etc to make sure the game fits) The GUI elements still work according to the screen position.

Is there any way to make the gui elements reposition themselves according to the REDUCED WIDTH AND HEIGHT.. which is actually not even reduced width, its just the camera forcing itself to be smaller... So maybe, there could be a way to have the GUI adjust according to the cameras position?

I hope you get what I'm saying and what I require. Please let me know if you would like to see specific scripts, or require screenshots of my problem

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 sang · Sep 19, 2013 at 06:31 PM

I think you could store the top left of the camera screen based on Resolution. So the width would be Screen.Height*9f/15f and the first X would be (Screen.Width - (Screen.Height*9f/15f))/2. And then use that as an anchor for your GUI Rects. also use Screen.Height as your unit. Assume you are talking about portrait resolution.

Comment
Add comment · Show 6 · 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 PuneetK · Sep 20, 2013 at 01:33 PM 0
Share

Yeah I'm talking about portrait.

I kind of get what you're saying, could you just elaborate a bit?

What does Screen.height * 9/15 denote? Like on the screen, what would that mean?

avatar image PuneetK · Sep 20, 2013 at 01:34 PM 0
Share

Also, for width, I just keep the default width right?

avatar image sang · Sep 20, 2013 at 02:04 PM 0
Share

Well, usually you may use something like this for GUI:

Rect exampleRect = new Rect(Screen.width*0.2f, Screen.height*0.1f, Screen.width*0.5f, Screem.height*0.1f);

Now you should use it like this float reducedWidth = Screen.Height*9f/15f; float firstX = (Screen.Width - (Screen.Height*9f/15f))/2;

Rect exampleRect = new Rect(firstX + reducedWidth *0.2f, Screen.height*0.1f, reducedWidth*0.5f, Screem.height*0.1f);

the Screen.height * 9/15 is equal to your clipped width :D

avatar image PuneetK · Sep 20, 2013 at 02:13 PM 0
Share

Thanks a lot! Here is my GUI code. Please have a look and let me know how it would work for this since I'm still slightly confused with the calculations :/

 group1 = new Rect (Screen.width *  0.1f, Screen.height * 0.01f, Screen.width * 0.8f, Screen.height * 0.05f);
 
 box1 = new Rect (0, 0, Screen.width * 0.4f, Screen.height * 0.04f);
 
 star_img = new Rect(Screen.width *  0.1f- Screen.height * 0.02f +Screen.width * 0.3f * barDisplay, Screen.height * 0.01f -Screen.height * 0.01f ,Screen.height * 0.05f,Screen.height * 0.05f);
 
 group2 = new Rect(0, 0, Screen.width * 0.3f * barDisplay,Screen.height * 0.04f);
         
 box2 = new Rect(0, 0, Screen.width * 0.4f, Screen.height * 0.04f);
avatar image PuneetK · Sep 20, 2013 at 02:14 PM 0
Share

In this code, Box 1 and Group 1 are the base images, Box2, group2, and star_img move according to some inputs by the user (its basically a health bar)

Show more comments

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

16 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

Related Questions

Simple GUI for walkthrough on mobile phone 2 Answers

How to Find Job Unity 3d Desainer 2 Answers

Why is Unity deleting my prefabs!? 1 Answer

2D Border doesnt allow the nutbomb gameobject to bounce 0 Answers

Object reference not set to an instance of an object 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