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.
Ok thanks. I'll go with the first one. Though should the InvokeRepeating be put in the Update method? Would it get called multiple times?
– SPIGSNah leave it out of update. It will continue to get called until you cancel the invoke.
– The_KrackenOk thanks again.
– SPIGS