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 superp · Feb 18, 2014 at 08:10 PM · screenzoomhealthbar

health bar that scale to the zoom

I am using GUI.Box to draw health bar and it works when i use fixed width and height: GUI.Box(new Rect(healthBarScreenPos.x, healthBarScreenPos.y, 2, 0.5, "Health");

However players can zoom in and zoom out and the health bar's size doesn't change because GUI doesn't shrink or enlarge based on camera zoom.

How would i translate my pixel values to screen that takes zoom level into account? I feel like GUI is not the right solution here. I am forcing it to shrink/enlarge programatically. Would using normal game object and changing their size work better? I am writing 2d game..

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 Nodgez · Feb 18, 2014 at 10:08 PM

You can set another camera to display the GUI. Make a new layer called "gui" and then make a sprite or quad(you're preference) that is set to the "gui" layer.

Then give this 2nd gui Camera the same scrolling method/script as the other camera and set it's culling mask to just be "gui".

you'll need to position the gui camera depending on where and how you want to draw the gui.

Have a look here

Comment
Add comment · Show 5 · 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 superp · Feb 19, 2014 at 05:32 AM 0
Share

i don't think that would work. the problem is that i am creating a tank game where each tank has its own health bar. I am not sure if adding camera for each health bar is a good idea. (there can be up to 9 tanks). really all i need is a GUI element that i can scale based on the camera size

avatar image superp · Feb 19, 2014 at 05:33 AM 0
Share

i guess better question would have been, how do i translate length in pixel to screen size?

avatar image Nodgez · Feb 19, 2014 at 08:37 AM 0
Share

Sorry, $$anonymous$$aybe I wasn't clear enough in my explanation.

You don't need 1 camera for each health bar. you just need to set each health bar's layer to "gui" and then you're 2nd camera will display everything that is on the layer "gui". so in total you will have 2 camera's. 1 as you're main to draw everything except the "gui" layer and then the other that draws only the "gui" layer.

I recommend having a look at the video if you haven't. The is a small part on GUI and camera's in it

avatar image superp · Feb 19, 2014 at 03:59 PM 0
Share

Hm... now i have GUI.Box in "gui" layer and i created another camera that only shows "guy" layer and i set its projection as orthographic because it is 2d game. When I zoom in/out, my script also change this 2nd camera's size but because GUI.Box is gui element, it's size doesn't change regardless of whether i put it in a different camera or within the main camera. How does putting it into a different camera make GUI stuff scale automatically? Or are you suggesting using non-GUI stuff like sprite? if that is the case, 2nd camera isn't necessary anyway? i am confused...

avatar image Nodgez · Feb 19, 2014 at 09:17 PM 0
Share

Yes you would use the sprite to display the health bar. the reason for the 2nd camera is so that the health bar will be displayed like a GUI i.e. on top of everything else in the scene using the the depth value of the camera. if you use the same camera for both the GUI and the tanks then there is a chance that some of you particle effects or other tanks will draw over the health bars blocking them from view.

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

19 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

Related Questions

Scaling GUI Label not working? 1 Answer

using objects bounds to zoom in object 2 Answers

Camera zoom while keeping an off-center object at the same screen co-ordinates 1 Answer

How do I rotate an object on one axis to face android touch? 0 Answers

Object resolution 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