Help with retroactive score multiplier
This problem has bugged me so many time in the past in different ways: the multiplier works fine, the only problem is that it affects my damageTaken retroactively (as my enemy moves closer or farther). How can I constantly update the score, save it somewhere and keep adding whilst using the multiplier?
Please post the actual code using the code formatting tool (101010 icon)
Answer by lgarczyn · Jan 05, 2020 at 08:28 PM
Why not store the health as a float? It will avoid damage being rounded down to 0.
Currently the only way to not affect all the hits taken is to convert the new damage to ints, which will be 0 most of the time.
Yep, it was the rounding that made the difference! Thank you :-)
I thought that the multiplier was retroactively changing the score, as my score seemed to be getting smaller at some stage, but now it works!
Your score will still change, if you get a shot further from your enemies, what you need is
damageTaken += percentageDamagePerDistance;
Answer by olidadda · Jan 06, 2020 at 09:18 PM
I actually solved it like this:
damageTaken = damageTaken + 1 * damagePerDistance;
Which is exactly equivalent to
damageTaken += 1 * damagePerDistance;
Which is equivalent to
damageTaken += damagePerDistance;
Which I suggested above
Right you are Sir! Yes that 1 was a tad redundant. Sorry, I'm rather new at this but thanks for your patience and help!
No worries, you'll get there in no time. Besides, verbose code that works is just as good, if that verbosity helps the readability.
Your answer
Follow this Question
Related Questions
How do i fix this problem 1 Answer
please help me with script. 1 Answer
error CS1525: Unexpected symbol `else'.Please help. 1 Answer
[macOS]Get Data from Serial Port in Unity 5.6.1 0 Answers
item not adding to list correctly! 1 Answer