I'm developing a tetris-style game, but geared towards chemistry. Instead of missing a complete line and punctuating, the user needs to form a molecule. For this, each element (H and C) is a different prefab. With this I need to identify if the element C has 4 H around it, to form a molecule and so punctuate and disappear only those blocks. Give my doubts .. how do I get the position that the C will fit the grid and compare if next to it has more 4H? I did it, but it did not work. Can you help me?
public void Verifica(){
while(gameStarted){
for (int y = 0; y < gridHeight; ++y) {
for (int x = 0; x < gridWidth; ++x) {
if (Grid [x, y] == (GameObject)Instantiate(Resources.Load("Prefab/C"))) {
Debug.Log ("Hello");//teste
if(Grid[x+1,y] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
cont++;
}
else if(Grid[x-1,y] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
cont++;
}
else if(Grid[x,y+1] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
cont++;
}
else if(Grid[x,y-1] == (GameObject)Instantiate(Resources.Load("Prefab/H"))){
cont++;
}
}
}Debug.Log ("Hello"+ cont); //teste
}
}
}
If it contains ++ == 4 closed the elements and scored. if not it will continue doing the verification with the rest of the blocks ..
NOTE: My blocks are formed only by prefabs C and H. that will fall randomly