Writing code in the Update section (Obstacle Course video Start and Update)


When adding number values in the update section for transform.Translate(0,01f,0,0) do you need to add
f (float) in only decimal numbers or any number you write in this line of code? Do you only add f (float) when you have an error?

the ‘f’ tells C# that the number is a float. In some cases it’s not necessary (a whole number doesn’t matter) but when you use decimals you need to do it. This is because C#'s default ‘decimal’ is a double and when you just write 12.34 C# will treat it as if it is a double. When you add the ‘f’, you are telling C# that this should be a float. It is shorthand for writing (float)12.34. Kinda. There are several others, like 12.34m for decimal (this is a type), 1234L for long, etc.

Bixarrio is right. Maybe you’ll be wondering why we use floats instead of double. Floats are more performant because they take up less space in memory. The “downside” is that floats are less precise than doubles but, in our game, float is precise enough, especially since transform.position and other things in Unity are of type float.

For further information, please see here:


See also:

Oh ok! Thank you for answering my question!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms