- Home /
 
More elegant way to constantly update player health algorithms.
Building a RPG game and the players health is dynamic and is calculated by combining the players base health with their stamina. The player can use a buff to increase his stamina throughout the game and therefore increasing the players total hit points and ultimately requiring the health to update.
Currently right now I am calling a function repeatedly in Update as shown;
 void Update() {
     characterHealthBar.value = characterHealth;
     characterManaBar.value = characterMana;
     // Control Max Health
     if (characterHealthBar.value >= characterMaxHealth) {
         characterHealth = characterMaxHealth;
     }
     CalculateCharacterMaxHealth (baseCharacterHealth, characterStamina);
 }
 
               This calls the following;
 public void CalculateCharacterMaxHealth(float _baseCharacterHealth, float _CharacterStamina) {
         characterMaxHealth = _baseCharacterHealth + (_CharacterStamina * 2);
     characterHealthBar.maxValue = characterMaxHealth;
 }
 
               Is there a better way to achieve this?
Answer by Der-Die-Das · Oct 12, 2017 at 07:09 AM
You could make characterStamina a Property and call the CalcualteCharacterMaxHealth function in the set function of the porperty.
Your answer
 
             Follow this Question
Related Questions
RPGStatSystem tutorial problem with clases visibility? 1 Answer
A real head-scratcher 0 Answers
Stats effecting the max Health Value 2 Answers
Getting XP when dies Help 1 Answer
C# Random Stats Distribuition 3 Answers