Array "size" question.

I have this variable

var scriptsNames: String[] = new String[0];

declared outside any function

now when I try to assign

function Start(){
scriptsNames[0] = "name1";
scriptsNames[1] = "name2";
scriptsNames[2] = "name3";
scriptsNames[3] = "name4";

Unity gives me errors. it can be fixed if I change, outside, in the Unity inspector size, over here.

but I suppose it can be changed inside a script, somehow? Is anybody willing here to show me how to access it, and change it to 4, for example, using scripting?

Thank you in advance.

The difference between a Unity array and a java script array is that Unity arrays cannot be resized so unless you know the exact size of an array before run time you should stick with java script arrays.

To make one of those you type:

var array = new Array();

and then all the basic array functions can be carried out on it like push and pop.

To create a Unity array (which are faster) with a fixed size you type:

var unityArray: String[];

function Start(){
   unityArray = new String[4];

You can switch between the two types using the array.ToBuiltin() function

P.S. It might not apply to you but I've noticed that creating large complex arrays may take more than one frame so trying to assign a value straight away sometimes leads to out of bounds errors (yes, sometimes..). To get around this I added an array check with a yield to wait for the array to finish initialising before assigning values to it.