Short way to add multiple Vector3s to an Array in C#

Hi All,
What is the short way of doing this?

Vector3[] positions = new Vector3[3];
void Start() {
positions [0] = new Vector3 (1, 0, 0);
positions [1] = new Vector3 (0, 0, -1);
positions [2] = new Vector3 (0, 0, 1);
}

Any help much appreciated!

You could try something like :

Vector3[] positions = new Vector3[3]{new Vector3 (1, 0, 0),new Vector3 (0, 0, -1),new Vector3 (0, 0, 1)};

In a more global way, you can initialize an array with :

Type[] array = new Type[nb elements]{element0, element1,....};
1 Like

Thanks Darholm.

QualitiesOfDarholm.Add("Awesomeness");

:slight_smile:

You’re welcome :wink:

You don’t to specify the number of elements, or the type. This does the same thing:

Vector3[] positions = {
    new Vector3(1, 0, 0), 
    new Vector3(0, 0, -1), 
    new Vector3(0, 0, 1)
};
1 Like

So it does, thanks Baste!