I’m trying to implement a SLOW health regeneration system… That will regenerate 1 health per 1 second. This is what i have in my health script ATM.
var regen : float = 1;
function Update () {
if(hitPoints < maxHitPoints) {
hitPoints += regen * Time.deltaTime;
}
}
This code works but only when i put my regen variable above 47 and that is ridiculously fast. I have searched through answers.unity3d for a while but couldn’t find a fix… Hopefully someone here knows how to fix this issue. Thanks for your time.
Griffo
August 1, 2013, 6:55am
2
var regen : float = 1;
var loop : boolean;
function Update () {
if(hitPoints < maxHitPoints && !loop) {
Health();
}
}
function Health(){
loop = true;
yield WaitForSeconds (1);
hitPoints ++;
loop = false;
}
Try this …
var timer : float = 0;
var regenPerSecond : float = 1;
function Update () {
timer += Time.deltaTime;
if(hitPoints < maxHitPoints)
{
if(timer >= 1)
hitPoints += regenPerSecond;
timer = 0;
}
}
}
or try this (without regen)
function Update () {
if(hitPoints < maxHitPoints) {
hitPoints += Time.deltaTime;
}
}
Sum of Time.deltaTime in per second = 1 as i know…