- Home /
Help with the code
why does plusDamage become 1 in the console when it is meant to be 1.1.
basically what i am trying to do is make it so what ever number you put in extra damage will be a percentage (e.g 10 will add 10% more damage to the damage outcome) by adding 100 then dividing by 100. put it in a calculator it says 1.1 which is the outcome i want, because down the bottom I times the outcome, but in unity it says 1.
Basic rules of calculation do apply to in JS / unity.
10 + 100 / 100 =11
(10+100) / 100 =1.1
Sorry I did not think it followed "Order of Operations" anyways in unity it is saying that 10 + 100 / 100 = 1? anyways I figured it out
Looks like this problem is solved. Please mark a answer as the right one or make a new one yourself which says how you solved it.
Answer by YoungDeveloper · Apr 15, 2015 at 09:52 AM
It goes from right to left, it will divide 100 by 100 and only then add extraDamage - add brackets the prioritize.
var plusDamage:float = (extraDamage + 100f)/100f;
dont worry, i got it to work in the function Start() the part where i did the maths there was alright, but for some reason it thought extradamage was 0, I know right once I figure that out It took me ages to figure it out. Until i stated the var in the function start. so 0 + 100 / 100 = 1, stupid glitches
it was 0 because it was public and most likely was 0 in inspector, there are no "glitches", only incompetence.
why would it be 0 in inspector, I never touched inspector. So if I were to state it was 10 then in the inspector It should be defaultly 10. or is it always 0 to make life harder. I can see why your answer is probably correct, because when I stated the variable in Start() it worked probably because it was changing it in the inspector when i started it