- Home /
Question by
DewDoughnut · Dec 04, 2019 at 03:51 PM ·
guihealthbarhealth-deductionhealth
unity health bar not losing health
I am trying to make a health bar and have it so once i click a object the numbers and bar itself go down. however this isnt working and i dont know what the problem might be.
{
public Text p_health_Text;
public Slider p_health_bar_slider;
public float p_current_health;
public float p_max_health;
// Start is called before the first frame update
// Update is called once per frame
void Update()
{
p_current_health = p_health_bar_slider.value;
p_health_Text.text = "" + p_current_health;
}
public void ChangeHealth(float amount)
{
p_health_bar_slider.value = p_current_health / p_max_health;
}
}
Comment
Answer by Casiell · Dec 04, 2019 at 04:46 PM
You take the "amount" parameter in your ChangeHealth method, but you are not doing anything with it. You should set p_current_health before you change the slider.
Your answer
Follow this Question
Related Questions
How to make my health decrease? 1 Answer
Health bar goes down instantly. 1 Answer
How do I make a custom health bar? 0 Answers
Help With Enemy Health bars 3 Answers
Healthbar not always working, someone please help! 2 Answers