Unity production ui blood bar

Silder

Silder schematic
Because you want to make a health bar, the H of the silder should be deleted
when you press the Silder Area, and it cannot affect the viewing effect. After you delete the value of the Silder to 0 or 1,
Effect picture when value is 0
When value is 1
you will find that there is one more health bar when it is 0. Fall, when it is 1, there is one less fall size.
Solution: The left and right of the

Fill Area are set to 0. The left and right of the
Fill are set to 0. The
effect is as follows: the
Insert picture description here
health bar is completed

Add a health bar control code

public int HP;//自己可以在外面设定血量大小,也可以自己直接设置血量大小
pravite int hpmax;//设定血量上限,用于控制血条的变化。
public Silider HpSlider;//血条的进度条,把UI的血条Slider赋值过来

private void Start()
  {
    
    
    hpmax = hp;//得到满血的状态。
     HpArticle();
  }

void HpArticle()
{
    
    
 	  hp -= Random.Range(10, 20);//随机减伤害,也可以自定义固定的伤害减值
      hpslider.value = (float) hp / hpmax;//让UI的Slider的value和hpslider的value一样来进行控制血条的变化
}

Guess you like

Origin blog.csdn.net/m0_48554728/article/details/114549718