Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

How to make a slider empty

Discussion in 'UGUI & TextMesh Pro' started by TheRaider, Feb 11, 2015.

  1. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    I have been trying to use sliders as progress bars. Is there anyway to make it completely empty? I always have a little bit showing even if the slider is at min value.
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,638
    This was an interesting one which took me a few attempts to figure out, always like a challenge.
    The answer in the end was very simple.
    1. Create a slider
    2. Delete the Handle Slide area (don't need that part for progress / heath bars)
    3. Set the Target Graphic to the Fill GO (child of Fill Area) - else it complains about not having a graphic
    4. (now for the important part)
    5. Set the Slider value to 0 - V.Important before altering anything else
    6. Select the Fill GO and set its width to 0
    7. Select the Fill Area GO and using the Rect Tool (in the editor toolbar) to alter It's Rect to fill the Background graphic (as shown below)

    upload_2015-2-11_17-5-47.png
    This makes the fill use the entire slider area over the background graphic and because the Fill starts at 0, it cannot be seen (so long as it does not stand up :D)
     
    PPLorux, cuongnmx, hballamco and 9 others like this.
  3. TheRaider

    TheRaider

    Joined:
    Dec 5, 2010
    Posts:
    2,182
    thanks :)

    I got it working with this advice
     
  4. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,638
    Glad to help. Always tip your waiter :D
    Might add this as an extra Editor Menu option to the UI Extensions repo (https://bitbucket.org/ddreaper/unity-ui-extensions) so it can be created with just a click :D. Not exactly a new control but at least an interesting template

    Added it to the develop branch of the project and will release with the next ver. Not entirely happy with how it looks from 0 - 0.1 on the slider. Tinkered around but couldn't improve it yet, may need to try a new Fill asset.
     
    Last edited: Feb 11, 2015
    rootsdub2 likes this.
  5. rootsdub2

    rootsdub2

    Joined:
    Apr 27, 2016
    Posts:
    2
    This was awesome!
     
  6. rootsdub2

    rootsdub2

    Joined:
    Apr 27, 2016
    Posts:
    2
    Be sure to change the transition from Color Tint to None as it will just tint the bar.
     
  7. ovirta

    ovirta

    Joined:
    Mar 20, 2015
    Posts:
    40
    I was also facing this with custom progress bar. Not quite sure if this is fool proof method but works on my slider at least without hickups. As my slider is using float in range of 0f ... 1f setting slider.value = 0f does not work.

    But setting it to float.NaN hides the bar completely.
     
  8. Gymhgy123

    Gymhgy123

    Joined:
    Jan 15, 2017
    Posts:
    4
    Works wonders. I was trying to make a health bar, and there was always a little sticking out. I just expanded it and made it off the canvas, so when it was at 0, the stub is outside of the canvas. (My health bar is at the corner) But that was really annoying and time consuming, so I found this thread, and voila! My health bar works.
     
    ovirta likes this.
  9. Divit

    Divit

    Joined:
    Jul 14, 2017
    Posts:
    4
    Thanks
     
  10. hballamco

    hballamco

    Joined:
    Nov 15, 2019
    Posts:
    3
    Thanks to 7 years ago
     
  11. PPLorux

    PPLorux

    Joined:
    Jul 29, 2017
    Posts:
    4
unityunity