List of Arrays?

Hi, all!

I constructed a grid for my enemies to use for positioning a while ago. The grid is a series of Vector3’s expressed in [ row, column ] form.

Well, I want to spawn randomly selected sets of enemies at specified places in the grid, so I made an enum called EnemyType which has 4 types: Probe, Tank, Bomb, and Null.

For easy placement on the grid, I made temporary variables in the start function that reference these types ( P, T, B, and o for null ).

I need to make an array of these 2D arrays so I can select individual [row, column] enemy sets to be iterated through and spawned.

However, Unity seems to either disagree with the idea of a [,], or I just don’t know how to write it.

Is this wrong?

#pragma strict

@HideInInspector
var easySets : EnemyType[,,];

//Creating contaners for our SetArrays

function Start () {
	
	var P : EnemyType = EnemyType.Probe;
	var B : EnemyType = EnemyType.Bomb;
	var T : EnemyType = EnemyType.Tank;
	var o : EnemyType = EnemyType.Null;
	
	// Setting up quick-access, one-key variables to create sets
	//EasySets = new EnemyType[2,7,7];
	easySets = [//START EASY SETS
	
	[P, o, o, o, o, o, P,
	o, P, o, P, o, P, o,
	o, o, P, o, P, o, o,
	o, o, o, o, o, o, o,
	o, o, P, o, P, o, o,
	o, P, o, P, o, P, o,
	P, o, o, o, o, o, P],
	
	[P, o, o, o, o, o, P,
	o, P, o, P, o, P, o,
	o, o, P, o, P, o, o,
	o, o, o, o, o, o, o,
	o, o, P, o, P, o, o,
	o, P, o, P, o, P, o,
	P, o, o, o, o, o, P]
	]; //END EASY SETS

}

If so, how should I write it? I just want to be able to extract a single 2D Array, iterate through it, and spawn enemies accordingly. The iteration and spawning part I already know how to do, so really I just need help on expressing it.

Thanks a ton! - YA

So your initialization there is creating a jagged array of EnemyType:

    var array : EnemyType[][];

This isn’t what you were expecting and I don’t think that there is a syntax to initialise a multi-dimensional array in any case.

If you wanted to make an array that was 3d jagged var array: EnemyType[][][] then you would need to initialize it like this:

   easySets = [
        [ 
          [P, o, o, o, o, o, P],
          [o, P, o, P, o, P, p],
          ...
         ],
         ...
        ];

This you could access using easySets[y][z] rather than easySets[x,y,z];