# Infect the blank cubes

I’m working on a “Game” for a university project, and i am not sure how to do my next section.

Currently, there are several cubes in a grid. the first player selects a cube to infect it with their colour (Red for player 1, Blue for player 2). This bit works fine, but what i want is for the cubes around an “infected” cube, to then become infected after player 2 takes their turn.

I’m not sure how to go about this, i tried with collision, and that didn’t work. I also thought about doing a sphere cast around the cube, and if there were any red cubes within the sphere, then it would turn red itself. But, i lack the knowledge to do this either.

My question is this, what would be the best way to infect blank cubes, that are next to red (Or Blue) cubes, after both players have taken their turns?

Just use an array that represents the game board, don’t bother with collisions and so on.

Here is a quick and dirty example of using Eric5h5’s grid suggestion.

This is just an OnGUI demo, and there are more efficient ways of handling it, but this should at least get you started.

When you attach this to an object, (camera maybe in a blank scene) you will get a grid full of G’s, Clicking on any of them will change the one clicked, and all of the ones around it to R.

Hope this helps,
-Larry

#pragma strict

``````var grid:String[,] = new String[10,10];

function Start(){
for(var x=0; x<10; x++){
for (var y=0; y<10; y++) {
grid[x,y]="G";
}
}
}

function OnGUI(){
for(var x=0; x<10; x++){
for (var y=0; y<10; y++) {
if (GUI.Button(new Rect(x*25,y*25,25,25),grid[x,y])){
grid[x,y]="R";
if (x>0)
grid[x-1,y]="R";
if(x<9)
grid[x+1,y]="R";
if (y>0)
grid[x,y-1]="R";
if (y<9)
grid[x,y+1]="R";
if(x>0 && y>0)
grid[x-1,y-1]="R";
if (x>0 && y<9)
grid[x-1,y+1]="R";

if(x<9 && y>0)
grid[x+1,y-1]="R";
if (x<9 && y<9)
grid[x+1,y+1]="R";
}
}
}
}
``````