Unity Slider, health bars

Unity Slider, health bars

我正在尝试为老板制作健康栏,我有一个 UI 滑块, 我有一个健康变量并将滑块位置设置为该变量, 但变量已满(高于 1)并且滑块显示已满,很棒, 但问题是,当我从满载下降时,滑块不会下降, 仅当低于 1 时。

这是我的代码:

public class SliderHealthBar : MonoBehaviour
{
    public Slider slide;

   [Range(0.0f, 1000)]
   public float health; // This is the health variable that exceeds 1, the max is at 1000
   public Gradient healthGrad; // This changes the length of the slider
   public Image img; // This changes the colour of the slider

   void Update()
   }
       img.color = healthGrad.Evaluate((float)health); // setting the color to health point on the gradient
       slide.value = health; // setting the slider value to health
   }

这里有什么问题吗?

谢谢!

我发现我可以将 public float Health 除以 boss 的最大生命值,这会使它介于 0 和 1 之间。

500 (health)/ 500 (max health) = 1

然后就是:

200 (health)/ 500 (max health) = 0.4

希望这对其他人有帮助。

:)

题解很简单。将健康除以一千。

img.color = healthGrad.Evaluate(health/1000f);