- Home /
Is there a way syntactically to assign all the values of a builtin array in one command?
A beginner question here on array syntax, I would like to assign all of the values in a builtin array at once something like,
myArray = new float[3]; myArray = (1,2,3);
I can of course set all of the values in the inspector, but that is not practical for large arrays. Is there a way to do this with a builtin array, or must I use a loop and set each array value individually?
Already answered, with JS and C# examples, Here: http://answers.unity3d.com/questions/5377/is-there-a-way-to-define-arrays-and-objects-literally-like-in-other-javascript-la
Thank you Duck and IJ$$anonymous$$, that is exactly what I was looking for!
Answer by IJM · Nov 18, 2010 at 07:17 AM
In C# you can do that like this:
public float[] MyArray = { 1, 2, 3, 4, 5, 6 };
And in JS you can do it like this:
var $$anonymous$$yArray : float[] = [2.5f, 5.0f, 10.0f];
Your answer
![](https://koobas.hobune.stream/wayback/20220613083524im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Sorting builtin arrays 2 Answers
Compare indices in an array of Vector2s 0 Answers
Basic javascript array declaration 2 Answers
Arrays in shaders 0 Answers
what is the correct syntax for the creation of arrays? 2 Answers