Unity Ugui implements segmented blood strips

Source: Internet
Author: User
Tags split

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



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.