- Home /
Health Regen
Hi my health regen code will not regen health in a full 1 number it regens it really fast in 0.01 number so the decimal in the health is visible i do not want that. here is an example.
class health : mono{
float health;
float regen;
float maxhealth = 100;
void start(){
health = 100;
regen = 1;
}
void Update(){
if(health < maxhealth & health > 0){
health += regen * Time.DeltaTime;
}
}
i have tried to put a Mathf.Round in place but it does not work any pointers? i code in C#
Answer by Stormizin · Sep 11, 2014 at 03:03 AM
You can cast your variable to just return INT number.
E.g:
int health;
health = (int) Mathf.Clamp01(Time.DeltaTime * 0.5);
this keeps health at complete max it never drops at all so what would be the point if the player could not die.
oh nvm my mistake it works but i just changed mathf.round to mathf.clamp01 and it worked i never needed to change it from an int.
Your answer
Follow this Question
Related Questions
Does Scripting Jump exist? (How To use/write goto) 3 Answers
Script Efficiency 1 Answer
My AI keeps flickering between stopping and moving. 1 Answer
Script only makes character run forward 1 Answer
Character Not Rotating 0 Answers