I have a script attached to a box that makes the player lose 20% of his maximum health on touch.
This is the script:
public Slider health;
void OnCollisionEnter(Collision col){
if(col.gameObject.tag=="Player"){
health.value=health.value-0.2f;
Debug.Log ("Hit "+health.value);
}
}
After that I started checking this script and moved player the way he could hit the harm-box multiple times before he dies. And then goes the weird part.
Each time player needs 7 collisions to become fully dead and this is the result list of the health slider value after each hit:
- 0.8
- 0.6
- 0.4
- 0.2
- 2.980232E-08
- 0.1
- 0.0
Could anyone please explain me why is this happening?