- Home /
Question by
Kansor · Sep 16, 2017 at 11:55 PM ·
health barhealth
Health Points
I have the animations of life created and the player already has life (100), how can I do to depending on the life to place an animation? Example: Player with 80 life = appearing second heart. I do not know if you explain me well by using GoogleTraslate :v
4.png
(111.0 kB)
Comment
you can easily use something like this
public GameObject hp100;
public GameObject hp80;
public GameObject hp60;
public GameObject hp40;
public GameObject hp20;
public GameObject hp0;
//these all should be disabled
void Start(){
hp100.SetActive(true);
}
void Damage(){
if(hp==100){
hp100.SetActive(true);
}
if(hp==80){
hp100.SetActive(false);
hp80.SetActive(true);
}
. . .
}
or you can use slider .
Best Answer
Answer by kryzodoze · Sep 17, 2017 at 04:11 AM
In your 'Healthbar' script, have some code that checks when your Hp == 80, and then add an Animator to that same GameObject and use GetComponent().Play(animationName).
Your answer
![](https://koobas.hobune.stream/wayback/20220612135016im_/https://answers.unity.com/themes/thub/images/avi.jpg)