1
I cannot identify my prefabs with the tags I have set, I have already added the tags to the prefabs as you can see below:
and my condigo:
public void Checks(){
for (int y = 0; y < gridHeight; ++y) {
for (int x = 0; x < gridWidth; ++x) {
if (Grid [x, y] != null) {
if (Grid [x, y].tag == "CARBONO") {
Debug.Log ("EXISTE C: ");
if (Grid [x + 1, y].tag == "HIDROGENIO") {
cont++;
}
if (Grid [x - 1, y].tag == "HIDROGENIO") {
cont++;
}
if (Grid [x, y + 1].tag == "HIDROGENIO") {
cont++;
}
if (Grid [x, y - 1].tag == "HIDROGENIO") {
cont++;
}
}
Debug.Log ("contador: " + cont); //teste
}
}
}
}
I put a checker to know if it enters the condition of a C in my grid, but as much as my grid appears Prefab C it goes straight through and does not do the rest of the checks.
The function that generates my prefabs randomly:
string GetRandomTetromino(){
int randomTetromino = Random.Range (1, 5);
string randomTetrominoName = "Prefabs/C";
switch (randomTetromino) {
case 1:
randomTetrominoName = "Prefabs/H";
break;
case 2:
randomTetrominoName = "Prefabs/C";
break;
case 3:
randomTetrominoName = "Prefabs/H";
break;
case 4:
randomTetrominoName = "Prefabs/C";
break;
}
return randomTetrominoName;
}
and the function that the generated Prefab plays at its coordinates:
public void SpawnNextTetromino () {
if (!gameStarted) {
gameStarted = true;
nextTetromino = (GameObject)Instantiate(Resources.Load(GetRandomTetromino(), typeof(GameObject)), new Vector2 (5.0f, 22.0f), Quaternion.identity);
previewTetromino = (GameObject)Instantiate (Resources.Load (GetRandomTetromino (), typeof(GameObject)), previewTetrominoPosition, Quaternion.identity);
previewTetromino.GetComponent<Tetromino> ().enabled = false;
} else {
previewTetromino.transform.localPosition = new Vector2 (5.0f, 20.0f);
nextTetromino = previewTetromino;
nextTetromino.GetComponent<Tetromino> ().enabled = true;
previewTetromino = (GameObject)Instantiate (Resources.Load (GetRandomTetromino (), typeof(GameObject)), previewTetrominoPosition, Quaternion.identity);
previewTetromino.GetComponent<Tetromino> ().enabled = false;
}
}
here is the repository of my game: https://www.dropbox.com/sh/epm4dxbiwcjaxvp/AAC-SzKcXtZzGhd71CS45KXra?dl=0
The code at first is OK, so we need the code that inserts the objects inside your Grid to evaluate the real problem.
– DH.
This function is the one that randomly generates my objects:
string GetRandomTetromino(){
 int randomTetromino = Random.Range (1, 5);
 string randomTetrominoName = "Prefabs/C";
 switch (randomTetromino) {
 case 1:
 randomTetrominoName = "Prefabs/H";
 break;
 case 2:
 randomTetrominoName = "Prefabs/C";
 break;
 case 3:
 randomTetrominoName = "Prefabs/H";
 break;
 case 4:
 randomTetrominoName = "Prefabs/C";
 break; 
 }
 return randomTetrominoName; 
 }
– Carlos Diego
Edit your question with this code, it will not only be readable as what comments are for mere details and for us users can ask questions, any useful information has to be in the question.
– DH.