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 Slvr99 · May 22, 2014 at 05:02 AM · camerascalinghudorthographic cameraoff-screen

How to scale 3D HUD with Camera Size?

I have a 3D HUD set up using some 3D models and an Orthographic Camera set to render as a regular 3D HUD should. The big problem here is whenever I change the screen size, the Camera's view scales to scale the view of the game and it leaves behind the 3D HUD causing it to appear off-screen/too far inward. Is there any way to move the 3D HUD to keep it in the upper-left of the Camera view regardless of the Camera View's size?

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

Answer by MD_Reptile · May 22, 2014 at 05:10 AM

The way I handled this, is by using a script to control button adjustments (to match screens of any size on android, but you could apply it here as well) and I would get the corners and areas of the screen (to position buttons based on where they are) like this:

 bottomLeft = Camera.main.ViewportToWorldPoint(new Vector2(0, 0));
         bottomRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 0)); 
         topRight = Camera.main.ViewportToWorldPoint(new Vector3(1, 1)); 
         bottomMiddle = Camera.main.ViewportToWorldPoint(new Vector3(0.5f, 0));

And I would take a buttons position and relocate it based on where the camera was like this:

 ThrustButton.transform.position = new Vector3((bottomLeft.x + 1), -1.25f, 5);

or:

 PauseButton.transform.position = new Vector3((topRight.x - 1.5f), (topRight.y - 1.25f), 5);

and this way I could forget about what screen size were using, and just decide how far from the corners to place buttons...

and as well I would scale the buttons based on this, something like:

 if(Screen.width >= 800)
         {
             fullSize = true;
             //Debug.Log("FullSize scale");
             buttonScale = 0.3f;
         }
         
         if(!fullSize && Screen.width >= 480)
         {
             midSize = true;
             //Debug.Log("MidSize scale");
             buttonScale = 0.275f;
         }

but this probably won't work changing it at runtime, as I set these values from the get go. Good luck!

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 Slvr99 · May 22, 2014 at 11:09 PM 0
Share

I'm not quite sure how to use the Camera variables. It has to be called from the main thread? Also, I'm using 3D models in the scene for the HUD, not buttons.

avatar image Fornoreason1000 · May 22, 2014 at 11:50 PM 0
Share

I think he's referring button scale as the the 3d Hud you have, you can make you'r own 3d HUD buttons that function like other buttons such as that which comes from the 2d GUI :) , also if your new to program$$anonymous$$g try to keep the adjustment code out of update and into where you change the screen.

avatar image Slvr99 · May 23, 2014 at 01:50 AM 0
Share

Yes, I know. I am not trying to make a button. I'm trying to make a 3D counter for a certain objective item. All I need is to keep it in the top-left of the camera view regardless of the size.

avatar image Fornoreason1000 · May 24, 2014 at 03:28 AM 1
Share

doesn't matter it's just a variable name, it doesn't affect the functionality of the code. you could have ElpehantEarScale ins$$anonymous$$d of button-scale it won't matter.

think of it this way. if a 3D button moves ans stays to the top left, so will your counter :)

avatar image Slvr99 · May 25, 2014 at 11:03 PM 0
Share

I figured it out. That is the answer, but I just didn't know how to call the Camera code right. I figured it all out and it works great! Thanks everyone!

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

24 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

Related Questions

Trying to use an orthographic camera in interior scenes 0 Answers

How do I implement orthographic elements into a perspective camera? 0 Answers

How Do I Build My Application To The Size Of The Camera 1 Answer

Set Orthographic Camera To Always Have Y Coordinate Start At Set Position 0 Answers

Align scene view camera to HUD camera? 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