Just to be clear on why you need that line. A Vector3 is an entire struct with a lot of data contained in it. When you make a Vector3 the compiler sets a lot of space for that Vector3. You need some way to find out where that space is.
So when you type
Vector3 myVariable = new Vector3(0,0,0);
myVariable is a small block of memory, that just holds a pointer to a big block of memory that has all your Vector3 data.
So Vector3 myVariable means make a small block of memory that will point to a vector3
new Vector3() = make a big block of memory that holds all the actual Vector3 stuff.
So in your case you just told the compiler to make a small block of memory pointing to null(nothing) and you will fill it in later. Since you never used the new Vector that @DanielQuick shows.
You might ask why would you ever just type:
Vector3 myVariable;
without the new keyword. Well maybe another function is going to send you back a Vector3 and so you don’t need to waste time/memory making a Vector3 yourself that your just going to throw away. Like this:
Vector3 myVariable;
void Start()
{
myVariable = GetMeAVector3();
}
private Vector3 GetMeAVector3()
{
Vector3 someVector = new Vector(0,0,0);
// Maybe some maths here to change that Vector3
return someVector;
}
Now the method GetMeAVector3 is making that big block of memory that holds the Vector3 and passing you back the address of it to stick in your variable myVariable. (so you didn’t need to use the new keyword in Start). But somebody somewhere has to use the new keyword to actual make that Vector3.
Finally… Why did making it public work? you never used the new keyword?
When you make something public in Unity, that lets Unity know to show it in the inspector. For the Inspector to work there has to actual be something there. So when you type in :
public Vector3 myVariable;
Unity is making the Vector3 for you behind the scenes. Somewhere in the code you can’t see is the line myVariable = new Vector3(); That way the inspector has something to work with.