c# – Difference between 0f and 0 on a Vector2 and Vector3 in Unity

The constructors for Vector2 and Vector3 look like this:

public Vector2(float x, float y);
public Vector3(float x, float y, float z);

Therefore, it doesn’t matter at all how you specify the number: 0, 0f or 0.0. The number will still be converted to float.

In which cases is it important to explicitly specify the type?

  1. Automatic deduce of the variable type:
var x = 0f; // x is float
  1. Loss of precision in integer arithmetic:
var i = 1;                          // i is int
var v1 = new Vector2(i / 2,  0);    // v1.x = 0f
var v2 = new Vector2(i / 2f, 0);    // v2.x = 0.5f

Read more here: Source link