2017-06-10 1 views
1

J'essaie de créer un système de regroupement d'objets pour mon WaveSpawner.Unity 5 2DArray, Mise en pool d'objets

C'est ce que je suis arrivé (objectPool est un tableau 2D):

objectPool = new GameObject[wave.Length,0]; 

//set columns 
for(int i = 0;i< objectPool.Length;i++) 
{ 
    objectPool = new GameObject[i,wave[i].numberToSpawn]; //set row for ech column 
} 


for (int p = 0; p < wave.Length; p++) 
{ 
    for(int i = 0;i<wave[p].numberToSpawn;i++) 
    { 
     GameObject gbj = Instantiate(wave[p].spawnObject); 
     gbj.transform.position = RandomizePositions(); 
     gbj.SetActive(false); 
     objectPool[p,i]= gbj; //fill 2D array 
    } 
} 

Cest l'erreur que je suis arrivé;

L'index de tableau est hors limites.

Répondre

2
objectPool = new GameObject[wave.Length,0]; 

Vous créez le tableau avec une taille de 0 dans la deuxième dimension.