- Home /
temporarily change variable(buff system)
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.
Answer by TheSOULDev · Sep 14, 2017 at 08:24 PM
Use Mathf.Clamp.
And example of a function to buff someone:
IEnumerator DamageBuff(int damageBuff, float Duration)
{
int difference = Mathf.Clamp(current + buff, min, max) - current;
current += difference;
yield return new WaitForSeconds(Duration);
current -= difference;
}
But if its for example a rune, that you insert(get stat), and remove, but you dont know when will it be.
Then you should either use a bool and WaitUntil() with lambda expressions or use a lambda expression (Func) as an argument of your function.
Your answer
Follow this Question
Related Questions
How often is the update function called ? 1 Answer
How would I go about making randomised guns, borderlands-style? 2 Answers
Played time? 2 Answers
Random time interval 1 Answer
Delaying a dynamic Variable(transform.position for Ex.) 2 Answers