- Home /
Problem with calculating damage, value returning 0
Hello guys I was trying to calculating the damage that the player would receive although if defense value is different from 0 the result will always be 0, i know I must be missing something but i cant figure out why, can anyone help?
I've tried to round it , to cast it as either float and double but couldn't fix it.
Thanks in advance.
Code:
float healthToLose = (damage * (100 / (100 + defense)));
health -= (int)Mathf.Round(healthToLose);
Comment
Best Answer
Answer by gordiri · Jan 24, 2018 at 08:21 PM
Its data type casting problem. Try to use 100f instead of 100. Or cast damage to float. Or use all of this
oh i see, i casted everything as float and it works perfectly now. Thank you.
Your answer
Follow this Question
Related Questions
Health and Damage [C#] 2 Answers
Decrase value on collision C# 2 Answers
Find angle between two gameobjects? 1 Answer
Multiple Cars not working 1 Answer