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 HNKMaster · Jan 27, 2015 at 03:58 AM · uihealthbarhp

Make health bar with various levels (boss)

Hi, I'm making a health bar for bosses using a slider, and because those bosses have a large amount of HP, I want that bar have levels, something like this:

https://dl.dropboxusercontent.com/u/108692101/BAR1.png

So, when I damage the boss, the bar depletes:

https://dl.dropboxusercontent.com/u/108692101/BAR2.png

And when that level is gone, the bar reverts its size and one of the spheres dissapear:

https://dl.dropboxusercontent.com/u/108692101/BAR3.png

Every level equals 100 HP, and when it decreases or increases over its limit, its level changes. I need help with this please.

Comment
Add comment · Show 1
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 AcE_fLoOdEr · Jan 27, 2015 at 06:24 AM 0
Share

Why don't you make two sliders, one red one yellow and position them on top of each other?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by DNRN · Jan 27, 2015 at 03:45 PM

I don't know what you have tried, or how you have implemented the way the damage is done. But you can create the health bar and sphere as a prefab, and put it in a folder named "Resources" then you can load both the health bar and the sphere runtime:

 GameObject bar = Instantiate(Resources.Load("BAR", typeof(GameObject)));
 GameObject sphere = Instantiate(Resources.Load("SPHERE", typeof(GameObject)));

Another approach could be to create a public reference to both the bar and sphere form your script as a GameObject, and load them runtime:

 var bar = Instantiate(BAR) as GameObject;
 var sphere = Instantiate(SPHERE) as GameObject;

And end up something like this: public int Health; public int Levels;

 public GameObject BarHolder;
 public GameObject Bar;
 public GameObject Sphere;

 // Update is called once per frame
 void Update () 
 {
     if (Health <= 0)
     {
         Levels--;
     }
     if (Health >= 100)
     {
         Levels++;
     }
 }

 private void RemoveLevel()
 {
     var bar = Instantiate(Bar) as GameObject;

     // This moves the bar to the right place, of the GameObject is placed right
     bar.transform.parent = BarHolder.transform;
     Destroy(Sphere);
 }

 private void AddLevel()
 {
     // TODO same as Remove just 
 }


When you need to remove the gameobject just call Destory(BAR) or Destroy(SPHERE). Here's some more reading: http://docs.unity3d.com/ScriptReference/Resources.Load.html http://docs.unity3d.com/ScriptReference/Object.Instantiate.html http://docs.unity3d.com/ScriptReference/Object.Destroy.html

Comment
Add comment · Show 1 · 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 HNKMaster · Jan 27, 2015 at 04:00 PM 0
Share

What I do is the HP bar access the status script of the enemy, so it can read the health data, and because the slider I'm using works with values from 0 to 1, I divide the HP data with a start value. This is how I work with UI Sliders:

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 
 public class _bossBar : _hud {
 
     public float hpBar;
     public float hpBarLimit;
     
     public Slider hpSlider;
     public Text levels;
 
     public _bossStatus bossStat;
 
     // Use this for initialization
     void Start () {
 
         hpBar = bossStat.hp;
     
     }
 
     void HP$$anonymous$$inus (){
         
         hpBar -= 150 * Time.deltaTime;
         
     }
     
     void HPPlus (){
         
         hpBar += 150 * Time.deltaTime;
         
     }
 
     // Update is called once per frame
     void Update () {
 
         base.Engine();
 
         hpBarLimit = bossStat.hpLimit;
 
         float newValue = $$anonymous$$athf.RoundToInt(hpBar)/hpBarLimit;
         hpSlider.value = newValue;
 
         if (hpBar >= bossStat.hp)
             HP$$anonymous$$inus();
         
         if (hpBar <= bossStat.hp)
             HPPlus();
 
     }
 }
 

I made the player HP bar like that, but I want the boss one be like the example I put at start, with more spheres the bigger amount of HP. It behaves like the $$anonymous$$OF special bar:

http://i.imgur.com/gTsRa$$anonymous$$r.png

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

21 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

Related Questions

Scale UI with distance 1 Answer

How do I create an undertale player health bar in C #? 1 Answer

Destroying UI elements problem 1 Answer

I need help with the player's health points 1 Answer

How to connect multiple sliders for health bar? 3 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