What is the difference between float and integer (C#)
I always use public float when I want to add a number to a gameobject but I just saw a unity tutorial that used integer, and I was kind of confused about what should I use in scripts.
Can anyone explain to me what's the difference between them?
Answer by Smitlord · Apr 01, 2016 at 02:05 PM
a float is a number that can have any number of decimals and an integer is a whole number it can be positive or negative
Thanks for explaining that. I have been using float which is wrong in my case.
Answer by Willox · Apr 01, 2016 at 02:23 PM
Integers are number which don't support a fractional component. On the other hand, floats are like integers, but they do support fractions too. So in your case, you may like to use int instead of floats, as you won't need to use a fractional number - you would call GameObjects 0, 1, 2... and not 0, 0.1f, 0.2f...
I was just gonna ask another question, but I think you answered it. So when using floats? I should write the (f) with the number in scripts? But when using integer I don't have to use (f) in scripts, just the number, right?
Your answer
Follow this Question
Related Questions
How can i improve this code so the random numbers don't repeat it self over and over? 2 Answers
How to make a number higher than Quintillion? (1000000000000000000) 1 Answer
-Then- statement for scipts. 1 Answer
How to know How many times the number was multiplied? 2 Answers
i cant find an easy way to make damage the same as traveltime 0 Answers