Method reference for parameters like Vector3 using default values

Similar to the following, the compiler will report an error:

public LoadInfo(string name, string url, string extension = "glb", Vector3 offset = Vector3.zero)
{
	this.name = name;
	this.url = url;
	this.extension = extension;
	this.offset = offset;
}

The reason for the error is that Vector3.zero is not a compile-time constant.

The default value of the last parameter offset should be changed to the following:

Vector3 offset = default

Another thing is to find that there is such a way of writing in C#, which is to add ? after the type, which means that the value type is allowed to have null values, similar to this:

Vector3? offset = null;

It means that this offset has no value, that is, there is no value, not even Vector3.zero.

Guess you like

Origin blog.csdn.net/ttod/article/details/130551369