• 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
5
Question by DaanSander · Jul 07, 2015 at 04:48 PM · gui

UI Slider not correctly filling

Hello, I was trying to create a health bar but I ran into a problem the slider is not filling even when I have the max value selected can someone help me?

Sorry for bad english alt text

unity.png (135.0 kB)
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 Mischa · Jul 07, 2015 at 05:18 PM 0
Share

The RectTransform values of the Fill Rect container are important for this one. $$anonymous$$ake sure they match the background of the slider.

2 Replies

· Add your reply
  • Sort: 
avatar image
14
Best Answer

Answer by Hellium · Jul 07, 2015 at 04:18 PM

Simply look at the Fill Area gameobject, you will see that there is a right padding in the RectTransform ...

Comment
Add comment · Show 2 · 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 Morgrhim · Jul 07, 2015 at 05:46 PM 1
Share

This is the correct answer. When you remove the slider handle you have to adjust the fill padding to account for it.

avatar image Beweeted · Dec 10, 2016 at 10:26 PM 2
Share

"Padding area" isn't labeled in the Unity UI. The values next to the pivot/anchor widget are the padding. For a normal bar, set the value for Left and Right to the same as the lower value between the two.

$$anonymous$$ine was 5 and 15. Setting both to 5 gave the expected result. Setting 15 to 0 overstretched it, making the bar bigger only while full - which could be a neat effect on it's own, if you want it.

alt text

rect-transform-padding.png (10.8 kB)
avatar image
0

Answer by YoungDeveloper · Jul 07, 2015 at 05:44 PM

I dont think you should be using slider for a health, why not simply change the width of the rect ransform considering the health amount?

Comment
Add comment · Show 4 · 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 Beweeted · Dec 10, 2016 at 10:28 PM 1
Share

1) Why reinvent the wheel, when Slider already does most of the work for you? 2) Because when you google "how to make a health bar in Unity", about 3,293,984 results come up saying "Use a slider bar".

avatar image YoungDeveloper Beweeted · Dec 11, 2016 at 06:40 PM 0
Share

if you dont care about loading times, especially on weak devices, such as mobile then go ahead. And the wheel thing you are talking about, this approach could be summarized as using nuclear reactor to turn single cart wheel

avatar image Necrohunter YoungDeveloper · Apr 15, 2020 at 07:31 PM 0
Share

i dont think a slider will break your game, i use it all the time for my games, it has like 0 impact to performance.

avatar image anthot4 · Jan 27, 2017 at 06:33 PM 0
Share

@YoungDeveloper Yes using a rect transform will have less performance head on a mobile device but I don't think it would be that large. It depends on what sort of game you are making.

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

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

GUI Depth not working 1 Answer

Weird missing texture/content glitch 1 Answer

Why is my Gui Selectiongrid not appearing 1 Answer

how can use GUI.Button? framework don't recognize or suggest the method 1 Answer

GUI Label/Text Area Doesn't Show Up Inside Scrollview 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