Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

[HUD] Stylish health life bar problem

Discussion in 'General Graphics' started by Kizumonogatari, Jul 10, 2015.

  1. Kizumonogatari

    Kizumonogatari

    Joined:
    Nov 30, 2014
    Posts:
    2
    Hi guys,
    Here I am, pretty new to Unity, trying to do all sorts of thing before taking it seriously.

    Here's what blocking me today:
    I want to do a sort of stylish health bar like this: http://image.noelshack.com/fichiers/2015/28/1436550908-resultwanted.jpg

    I looked around for some tutorial, but all of them giving an output like that more or less: http://image.noelshack.com/fichiers/2015/28/1436551078-resultnotwanted.jpg

    Instead of resizing, are there any ways to crop the yellow life bar ?

    Thank in advance.
     
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    As with most programming problems, there are many, many solutions. Here's what I recommend:

    Make 2 UI images, both with the yellow image, but turn the rgb values down on the one that renders in back so it appears greyscale. On the colored image, set the image type to "Filled" and the fill method to "Horizontal", then you'll be able to set the fill amount in-code (0 to 1). To access an image in-code (or any unity UI), you must have "using UnityEngine.UI;" at the top of your script

    Best of luck!
     
    theANMATOR2b likes this.
  3. Kizumonogatari

    Kizumonogatari

    Joined:
    Nov 30, 2014
    Posts:
    2
    Oh god, thank you, it worked!