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 Xan_Schneider · Apr 08, 2015 at 02:47 AM · canvasgameobjectshealth

How to canvas health bars on top of every alive unit on screen??

I've seen many posts related, but non has worked the way I want to. I want to create a health bar asset (the health bar images, one on top of the other, sliding left to simulate health reduction) and asign one health bar asset to each unit (following eath unit) that is currently on screen "isVisible;" and alive "GetComponent().alive == true;". If possible, all health bars to show on a single canvas.

I'm having a hard time linking the objects with the canvas asset, can't even make the health bar asset appear on screen. I don't even know how to approach this... I'm pretty new to all this programming thing. Can anyone give me some advice on how I can achieve something like all this I described here??

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 AlwaysSunny · Apr 08, 2015 at 02:46 AM

In this case, I'd want a manager for any UI element that should be driven in world space, such as health bars, objective indicator icons, speech bubbles... Anything like that falls under one logical umbrella: World-space UI elements that come and go as needed.

Then there are screen-space UI elements that come and go as needed; e.g. prompts or feedback messages that appear for a moment; I'd probably manage them separately. Then there's screen-space elements that don't need dynamic positioning, such as a HUD, which I'd want in a third script. These three scripts I'd tie to a singleton UI manager which I could call anywhere in the project.

Each script holds prefabs of each unique UI object in the game, and will expose public methods which streamline the creation of the requested object. Ideally you want to be able to request the objects with a single line of code:

 myHealthBar = UIMan.WorldSpaceTemps.Create("HealthBar", thisAgent);


Decide who will make the decision about requesting a new temporary world-space health bar; isVisible and isAlive and myHealthBar == null sound like fine checks; if all three are true, request a new health bar from the world-space-ui-manager. The new health bar could be tracked in a collection of active health bars and/or handed to the corresponding agent to manage, e.g. if !isVisible or !isAlive and myHealthBar != null, destroy myHealthBar.

The health bar object can be as complex as you like, but give it its own UIHealthBar script so you can manage that complexity with ease. It can position itself to correspond to its agent's world position, and set its own slider values based on its agent's health percentage. Keeping a collection of them in the world-space-ui-manager will allow group changes like destroying all health bars when the game ends.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Should UI Canvas be used for games similar to 2048? 1 Answer

How to display the gameobjects of a worldspace canvas in front of gameobjects of screen space overlay canvas? 1 Answer

add scores to player score panel after running into a object that explodes on collision 1 Answer

(4.6 UI) Canvas position resetting itself to (0,0,0) when instantiating a new prefab with the canvas as child? 2 Answers

How to fade gameobjects scrolling toward the 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