Arrays allow you to store multiple objects in a single variable.
function Start () { var arr = new Array (); // Add one element arr.Push ("Hello"); // print the first element ("Hello") print(arr[0]); // Resize the array arr.length = 2; // Assign "World" to the second element arr[1] = "World"; // iterate through the array for (var value : String in arr) { print(value); } }
// Exposes an float array in the inspector, // which you can edit there. var values : float[];function Start () { // iterate through the array for (var value in values) { print(value); } // Since we can't resize builtin arrays // we have to recreate the array to resize it values = new float[10]; // assign the second element values[1] = 5.0; }
function Start () { var array = new Array (Vector3(0, 0, 0), Vector3(0, 0, 1)); array.Push(Vector3(0, 0, 2)); array.Push(Vector3(0, 0, 3)); // Copy the js array into a builtin array var builtinArray : Vector3[] = array.ToBuiltin(Vector3) as Vector3[]; // Assign the builtin array to a js Array var newarr = new Array (builtinArray); // newarr contains the same elements as array print (newarr); }
length | The length property of the array that returns or sets the number of elements in array. |
---|
Add | Adds value to the end of the array. |
---|---|
Clear | Empties the array. The length of the array will be zero. |
Concat | Concat joins two or more arrays. |
Join | Joins the contents of an array into one string. |
Pop | Removes the last element of the array and returns it. |
Push | Adds value to the end of the array. |
RemoveAt | Removes the element at index from the array. |
Shift | Removes the first element of the array and returns it. |
Sort | Sorts all Array elements. |
Unshift | Unshift adds one or more elements to the beginning of an array and returns the new length of the array. |
Add | Adds value to the end of the array. |
---|---|
Clear | Empties the array. The length of the array will be zero. |
Concat | Concat joins two or more arrays. |
Join | Joins the contents of an array into one string. |
length | The length property of the array that returns or sets the number of elements in array. |
Pop | Removes the last element of the array and returns it. |
Push | Adds value to the end of the array. |
RemoveAt | Removes the element at index from the array. |
Shift | Removes the first element of the array and returns it. |
Sort | Sorts all Array elements. |
Unshift | Unshift adds one or more elements to the beginning of an array and returns the new length of the array. |