I’m scripting player stats and was wondering what would be the best approach for regenerating health/stamina/magic? what would be the easiest and/or what would be the most efficient?
Something like this?
float maxhealth = 100; //maximum health
float curhealth = maxhealth; //current health
void SomeMethod(){
InvokeRepeating("RegenHealth", 1, 1);
}
void RegenHealth(){
if (curhealth < maxhealth){
curhealth += 2;
}
if(curhealth >= maxhealth){
curhealth = maxhealth;
CancelInvoke();
}
Or something like this?
void Update(){
if(curhealth < maxhealth){
curhealth += 2 * Time.deltatime;
if(curhealth >= maxhealth){
curhealth = maxhealth;
}
}
}
Or is there another way of doing it? Answers appreciated.