You can use NGUI to create a colored role blood bar and load the progress bar.
When creating a blood strip, you can display different colors based on the amount of blood, and you can simply encapsulate UISider and UILabel.
UISprite: NGUI genie image component
Atlas: image sets
Sprite: Image in the selected image set
Sprite Type: Simple (scale the image to the specified size without processing it), Sliced (small-sized image to fit the size)
Tiled (fill the area in the form of bricks without scaling the image), Filled (fill area), Advacced (advanced, customizable edge pixels)
If it is a small image, you need to modify the sprite type to achieve the effect.
Make color slide:
A. Add a Progress Bar in the Widget Tool. a UISider (NGUI compent) is added by default)
Value: Percentage
Alpha: Transparency
Steps: Step threshold
Appearance: Features
A. Foreground (Foreground image)
B. Background (Background image)
C. Thumb (mobile indicator)
D. Direction (slide Direction)
On Value Change: Event distribution when sliding
B. Add a Script on the Progress Bar to change the color of the Progress.
public class UISliderColors : MonoBehaviour{public UISprite sprite;public Color[] colors = new Color[] { Color.red, Color.yellow, Color.green };UIProgressBar mBar;void Start () { mBar = GetComponent<UIProgressBar>(); Update(); }void Update (){if (sprite == null || colors.Length == 0) return;float val = mBar.value;val *= (colors.Length - 1);int startIndex = Mathf.FloorToInt(val);Color c = colors[0];if (startIndex >= 0){if (startIndex + 1 < colors.Length){float factor = (val - startIndex);c = Color.Lerp(colors[startIndex], colors[startIndex + 1], factor);}else if (startIndex < colors.Length){c = colors[startIndex];}else c = colors[colors.Length - 1];}c.a = sprite.color.a;sprite.color = c;}}When Sprite is specified as the foreground image of the current Progress Bar
E. Create a UILabel in the current Prgoress Bar to distribute the event to the UILabel
Test code:
public class Tt : MonoBehaviour {private UISlider slider;// Use this for initializationvoid Start () {slider = GetComponent<UISlider>();slider.value = 0;}// Update is called once per framevoid Update () {if(slider!=null) {Debug.Log(slider.value);slider.value += 0.0005f;}}}
Use of Unity3d NGUI (5) (UISprite & UISinder for colored blood strips)