What is the problem with the following way to create an Array of prefabs?
I want to instantiate randomly selected prefabs contained in this Array at certain positions.
So I began creating the js that will do this. Till now, the js contains only the following lines:
var spawnObjects : GameObject[];
var spawnObject0: GameObject;
var spawnObject1: GameObject;
var spawnObject2: GameObject;
var spawnObject3: GameObject;
var spawnObject4: GameObject;
var spawnObject5: GameObject;
var spawnObject6: GameObject;
function Awake () {
spawnObjects[0] = spawnObject1;
spawnObjects[1] = spawnObject1;
spawnObjects[2] = spawnObject2;
spawnObjects[3] = spawnObject3;
spawnObjects[4] = spawnObject4;
spawnObjects[5] = spawnObject5;
spawnObjects[6] = spawnObject6;
}
At the Inspector (while the object the js above is attached to), I have filled the slots that appear, with the desired prefabs.
When I hit play, I get the following warning:
IndexOutOfRangeExeption: Array index is out of range.
The console points at line 10 of the js (spawnObjects1 = spawnObject1;).
This is how the Inspector looks like when I select the object that has this js attached (I cannot understand why the Size of the array is 0):