Hi,
I’m trying to create a 50x50 2d Array of tiles, it works perfectly however in the Hierarchy after I run the code, I get a bunch of “New Game Object” GameObjects with no properties.
Could you tell me why and eventually how to fix it? Everything else in the code works fine and gets me the desired results.
Thank you.
public class Matrice : MonoBehaviour
{
public GameObject referenceTile;
GameObject[,] griglia = new GameObject[50, 50];
Vector2 grigliaPos;
// Start is called before the first frame update
void Start()
{
generaGriglia();
}
void generaGriglia()
{
for (int i = 0; i < 50; i++)
{
for (int j = 0; j < 50; j++)
{
GameObject gridSpace = new GameObject();
gridSpace = referenceTile;
float posX = i -24.5f;
float posY = j -24.5f;
gridSpace.name = "X: " + posX + " " + "Y: " + posY;
gridSpace.gameObject.tag = "MapTiles";
griglia[i, j] = (GameObject)Instantiate(gridSpace, new Vector3(posX, posY, 0), Quaternion.identity);
}
}
}
}