Hello,
I am actually trying to make a checkers game. I’m trying to create a board (10x10) that contains 100 tiles (public Dictionary<float, Tile> tiles = new Dictionary<float, Tile>();
) of the class Tile. Here is my code to make them spawn :
void Awake () {
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
Tile tile = GetComponent<Tile> ();
id = id + 1;
tile.id = id;
tile.coordinates = new Vector2(i, j);
tile.piece = default(Piece);
tiles[id] = tile;
}
}
}
But the problem I have is that when i want to read this dictionary :
foreach (KeyValuePair<float, Tile> entry in boardComponent.tiles) {
GameObject tileObject = new GameObject("Tile" + entry.Key);
tileObject.transform.parent = GameObject.Find ("Board").transform;
tileObject.AddComponent<Tile>();
Tile tile = GameObject.Find("Tile" + entry.Key).GetComponent<Tile> ();
tile.coordinates = entry.Value.coordinates;
}
All my tiles coordinates are Vector2(0,0) and I don’t understand why. When i Debug.Log(tile.coordinates);
in the for loop, I’m getting right values, but when i push them to the dictionary, it seems like they are loss. What can i do to keep those coordinates ?
Thank you.