We can see heroes like League of Legends and other games in the head of the blood bar display is not a solid color, but according to the amount of blood to display a certain amount of lattice, this way is obviously more friendly, more beautiful, in fact, our game also want to achieve such an effect, then how to do it. Create n multiple small lattice images at the same time depending on the amount of blood. This is obviously unreasonable; split the picture by creating n multiple split lines at the same time as the amount of blood. It's not reasonable either.
So today I will be in a very simple way to achieve this effect, of course, no difficulty, only the Ugui slider to make some changes can be.
First, we create a slider, delete his handle, tick whole Numbers (change the value by integer), presumably this:
Add our script bloodimage to the fill rect target, delete the original image component, assign a texture to bloodimage, and the texture must be of type texture:
Bloodimage inherit to Rawimage, so can only receive texture type of picture source, his main responsibility is according to the length of the blood bar to the picture to be recycled.
Using Unityengine;
Using Unityengine.ui;
public class Bloodimage:rawimage {
private Slider _bloodslider;
protected override void Onrecttransformdimensionschange ()
{
base. Onrecttransformdimensionschange ();
Gets the blood bar
if (_bloodslider = = null)
_bloodslider = transform.parent.parent.getcomponent<slider> ();
Gets the value of the blood bar
if (_bloodslider! = null)
{
//refreshes the display of the blood bar
float value = _bloodslider.value;
Uvrect = new Rect (0,0,value,1);}}}
Here, basically OK, you want the blood bar to show how many small squares, you can change the slider's Max Value property (maximum value) on it.
The effect diagram is as follows:
Of course, if you have better material, this blood bar will be more beautiful.
third, I have bloodslider into a plug-in, import the plug-in, you can directly create Bloodslider in the scene.
Plugin Link: http://download.csdn.net/detail/qq992817263/9660453