- Home /
How do I add something on to a float.
Hello.
I have had a problem for quite some time and it is the only major problem in my project right now. After many google searches I still could not find the answer.
I am trying to add points onto my point float.
points = playertransform.position.z;
I have tried things such as points = points += playertransform.position.z
but that just made it go up faster. Any help is appreciated
It looks like you have a variable named points and you are setting it to match the z axis value of playertransform?
Then your next example you are adding itself to itself plus the z axis value?
The += operator is shorthand for adding a value. So ins$$anonymous$$d of having to do value1 = value1 + value2, you just use value1 += value2.
If you can explain what you are trying to achieve exactly, and what results you are getting, including any code or console output, the community may be able to help. It's a little hard to understand exactly what you are trying to do though.
Answer by marquizzo · Apr 16, 2019 at 06:59 PM
You probably just want to add the z-position once. You have two alternatives:
points += playertransform.position.z
points = points + playertransform.position.z
Both these approaches do the same thing.
Your answer
![](https://koobas.hobune.stream/wayback/20220612195609im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity Float to db 2 Answers
Float not Multiplying 1 Answer
Primitive data types (for code, not modeling) 2 Answers
Bad result on a rest between 2 floats 1 Answer
Float subtracting in increments of 1 no matter what value it's subtracted by 0 Answers