I want to make damage and heal system for my game. The problem is, when the player takes damage and heals at the same time, only one of the event happened while the other one is abandoned. For example:
I think instead of changing the HP directly, I should calculate (Heal - Damage) first then add it to HP, but how do I calculate (Heal - Damage) without other event overlap problem to happen?
The only solution I can think of is to make a “calculation folder”. Everytime the player is healed or damaged, an IntValue representating one source of HP changes will be created. The script will get all children of the folder and get the (Heal - Damage) value by iterating through all IntValues every some miliseconds. This is the visualization:
But is it efficient? Is there any other approach that is more efficient and doesn’t require the game to iterate all of the children every some miliseconds?