temporarily change variable above/below min/max , and reverse.

Hello everyone! Im currently making buff system and occured a problem. Simple example.

I have stat Damage. int current = 10; int max = 15; int min = 5;

I have Buff,that increases/descreases damage by 6;

1)current(10) + 6 = 15(bigger than max(15), so current equals max)

Buff changed stat by 5,not by 6, so the question is, how can i know what value to return?

What is the best way to save info about actual value that was changed,because everytime making variable isnt great idea, when you change variable above/below max/min, and than need to return that value.

First idea i had, to create a method ChangeValue(string ChangeName,int value) that stores in a list an object, with name and actual value, so i can access it later, but i dont think its a great way to do that.

Any help is appriaciated. If you are confused, ask, i will try to do my best to explain.

for buffs, don’t modify the base stat. have an extra variable that represents the new modified stat and everything will use that instead. base stat changes typically only hold changes that are meant to be irreversible (like stat gain from leveling up). that way when the buff expires your base stat remains unaffected.

I guess I’m confused about why you want to know how much it tried to change, instead of by how much it actually changed.

Min/max to me means just that… minimum and maximum. There’s no going outside of min/max, otherwise they’re not really min/max.

It’s not really the stat’s problem to keep track of by how much it “tried” to change. Just slap in a Mathf.Clamp to keep it within min and max, and keep a copy of “Buff” elsewhere where you need it.