wysepka

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

Scrollbal size going beyond the UI canvas.

When changing size in Canvas scrollbar properties, my HealthBar going far beyond the expand. Dont know what possibly could go wrong,

  • crew

    Sometimes it'll scale into a negative value. Maybe something isn't properly lined up within your UI elements so any scale adjustment multiplies the effect for the children elements as well. 

  • crew

    I didn't want to leave you with a bit of a vague answer, so I recreated this in Unity 2018. It can be a bit of a pain as the UI can sometimes readjust and you'll need to re-parent things at times. Here is the link to the completed scene: UI Health Bar

    Key things to look out for, make sure the anchor point is to the left of the canvas (pinwheel looking icon) for the health portion of the UI. What I would do differently than in the video is to create the mask and health and keep them separate, then add the scrollbar to the canvas. Scale the mask and health to match the entire size of the canvas, move the anchor point of the health to the left, then move the health under the mask as a child. From there adjust the mask group to look like a health bar. 

    It's more complex than it should be, usually I use a simpler method which just involves using a health bar image and adjusting the fill type of that image. Take a look at this lesson to find out how I do it now: https://cgcookie.com/lesson/loading-bars