difference between using var x,y,z from 3 different var

so my question might sound wierd but i came across alot of people doing the following.

GameObject x,y,z

GameObject x;
GameObject y;
GameObject z;

is there any difference from doing either? or is this a unity only thing? cause i have actually never seen it

There is no difference at all except for how code looks visually.

in what way do you look at people using the method of only using one varible? instead of 3?

Usually, if I store a vector and intend to use its components separately I’ll store it in one variable.

Vector3 terrainSize = terrain.terrainData.size;

//Check if terrain size is uniform
if (terrainSize.x != terrainSize.z)
{
   Debug.LogErrorFormat(this.name + ": size of \"{0}\" is not inform at {1}!", terrain.name, terrainSize.x + "x" + terrainSize.z);
   this.enabled = false;
}
float terrainSizeX = terrain.terrainData.size.x;
float terrainSizeZ = terrain.terrainData.size.z;

//Check if terrain size is uniform
if (terrainSizeX != terrainSizeZ)
{
   Debug.LogErrorFormat(this.name + ": size of \"{0}\" is not inform at {1}!", terrain.name, terrainSizeX + "x" + terrainSizeZ);
   this.enabled = false;
}

Both methods will work, I suppose it’s a matter of preference and/or readability :wink:

OP is not referring to a vector in any way, but rather the stylistic way of how to declare multiple variables of the same type.

Both of the examples you are showing are declaring 3 variables named x, y, and z. The only difference is syntax. I personally tend to use the second syntax because to me it’s easier to read. But it just comes down to preference, or if working with a team whatever coding standards are agreed upon.

1 Like