kab5417

3 answers · asked · Lesson: Creating a UI Health Bar · Course: C# Bootcamp for Unity

At 10:38 it clearly shows less than "10" left on the health bar, the relationship between the size of scrollbar and the cu...

At 10:38 it clearly shows less than "10" left on the health bar, the relationship between the size of scrollbar and the current health is somehow not correct.
  • crew
    At 10:38 I'm not seeing anything on the health bar, where are you getting 10 left?
  • I just mean that the proportion seems off. It takes away 10 hp when you click, then takes away another 10 and continues, but on the last click there isn't the same amount left to take 10 away. On my end, when I followed along I ran out of health bar before I ran out of curHealth and when I'm looking at the canvas slider bar, when I slide the size bar it moves the mask too far and ends up with a red x to the left of the HP bar in the scene view.
  • crew
    I think you just resolved your own issue. The issue is that your mask is moving outside the bounds of what you're seeing. So it thinks the health bar area is bigger than it really is. In the video I made the health bar slightly smaller than the length of the canvas which may have caused issues. You can actually apply the scrollbar component to the mask itself as well, just add the script to the mask instead. As long as the mask and the health bar match in size you shouldn't have any issues. If the object that has the scrollbar is a different size than the mask you'll have issues.