• 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 H3yPlaya · Nov 07, 2018 at 10:47 PM · healthbar

Moba Styled Health Bar Divisions

I am trying to get a Moba styled health bar, as in if I have 1000hp there should be 9 lines like this: 100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp|100hp And if I have 2000hp I should have 19 lines, and so on and so forth. Here is my code, I am having trouble:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class PlayerHealth : MonoBehaviour {
     
     public int MaxHealth = 100;
     public int CurrentHealth = 0;
     public int BarWidth = 50;
 
     void Awake() {
         CurrentHealth = MaxHealth;
     }
 
     void Update() {
         float pixelsPerHP = (float)BarWidth / MaxHealth;//~0.6f
         int everyHundredHPLineOffset = Mathf.RoundToInt(pixelsPerHP * 100);//~60
 
         int numberOfLines = Mathf.RoundToInt((float)MaxHealth / 100);
         for (int i = 1; i < numberOfLines + 1; i++) {
             int offset_current = i * everyHundredHPLineOffset;
             //Draw line using offset_current
         }
     }
 }

But I don't know how to draw the line. :( Does anyone know? Please help me. Thanks!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by hectorux · Nov 07, 2018 at 11:14 PM

Try a horizontal Layout, and for each 100hp, instantiate one new. Then for the lenght of the array of vars, divide it for the total lenght of the bar, and set that value to the scale of ehvery bar(of 100 hp)

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
avatar image
1

Answer by Matt1000 · Nov 07, 2018 at 11:05 PM

Where are you trying to draw this line? Something tells that you probably should be using GUI. If you are you actually need to create an image of a line next to the image of the health.

But you really should be using GUI for this...

Comment
Add comment · Show 3 · 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 H3yPlaya · Nov 08, 2018 at 01:45 PM 0
Share

Yes, thank you that's what I mean. But how?

avatar image H3yPlaya · Nov 08, 2018 at 01:46 PM 0
Share

Oh, and the place where I need to draw it is below the comment //Draw line using offset_current

avatar image H3yPlaya · Nov 10, 2018 at 03:15 PM 0
Share

Hello? I was kinda hoping for an answer. @$$anonymous$$att1000

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

95 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 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 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 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

Splitscreen w/ different GUIs on each camera 2 Answers

Healthbar not always working, someone please help! 2 Answers

GUI.HorizontalScrollbar won't change it's height 1 Answer

GuiTexture above 3D objects 1 Answer

NullReferenceException: Object reference not set to an instance of an object 1 Answer


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