- Home /
Question by
TranceDreams · Dec 16, 2020 at 02:08 AM ·
javascriptfunctionsdeltatimehealth bar
Ramp Hp function by speed
Hello. I call this function to roll the hp down when the character is hit with damage, or ramp it up when given food or a potion, instead of just saying hp -= x;
function HpRoller(amt : float, roll : int){
while(amt >0){
amt -= 1 *Time.deltaTime;
Hp += roll * Time.deltaTime;
yield;}
}
for damage for example, i would call it with a negative number, so PlayerJs.HpRoller(200, -1); and for potions PlayerJs.HpRoller(50, 1);
I would just like for it go faster then 1 per second. How do I correctly multiply it by Time.deltaTime to ramp faster?
I tried this but realized it would not accurately ramp Hp
function HpRoller(amt : float, roll : int){
while(amt >0){
amt -= 1 * (15*Time.deltaTime);
Hp += roll * (15*Time.deltaTime);
yield;}
}
Comment
Your answer
Follow this Question
Related Questions
yield WaitForSeconds preventing further actions. 1 Answer
Slower Ladder 2 Answers
assigned function declaration in unity javascript for different types 1 Answer
How to pass function as parameter to function? 1 Answer
Health System? 1 Answer