void CreateHexTileMap() { for (int x = 0; x <= mapWidth; x++) { for (int z = 0; z <= mapHeight; z++) { GameObject TileGo = Instantiate(hexTilePreFab); if (z % 2 == 0) { TileGo.transform.position = new Vector3(x * tileXoffset, 0, z * tileZoffset); } else { TileGo.transform.position = new Vector3(x * tileXoffset + tileXoffset / 2, 0, z * tileZoffset); } ClickableHex ct = TileGo.GetComponent <ClickableHex>(); ct.tileX = x; ct.tileZ = z; ct.map = this; setTileInfo(TileGo, x, z); } } }
void GenerateMapVisualHexes() { double r = 0, c = 0, z = 0; for (int x = 0; x < MapSizeX; x++) { if (x % 2 == 0) { r = 0; } else { r = 0.95; } for (int y = 0; y < MapSizeY; y++) { HexType ht = hexType[Hexes[x, y]]; //different levels of hex types (buffs, mountains, debuffs) switch (Hexes[x, y]) { case 0: z = 0; break; case 1: z = 0.5; break; case 2: z = -0.5; break; default: z = 0; break; } //Used to set the prefab on the map as well as able to get the object that was clicked on. GameObject gObject = (GameObject)Instantiate(ht.VisualHexPrefab, new Vector3((float)r, (float)c, (float)z), Quaternion.identity); gObject.name = "Hex_" + x + "_" + y; gObject.transform.SetParent(this.transform); gObject.GetComponent <ClickableHex>().clearSelectedUnit(); ClickableHex clickhex = gObject.GetComponent <ClickableHex>(); clickhex.HexX = x; clickhex.HexY = y; //Debug.Log(clickhex.HexX + " , " + clickhex.HexY); clickhex.map = this; r = r + 1.9; //X coordinates } c = c + 1.6; // Y coordinates } }