/* * Initialize a single cell at a given offset from the origin (x, z) following these steps: * - Instantiate a new HexCell * - Set this grid as the HexCell's parent * - Position the cell's center: * - Shift each x position by the minimum radius of a cell (this are "pointy" hexes) * - Shift each Z position by the maximum radius of a cell _plus_ half that shift again (1.5 * MAX_R) * - In every odd row, shift each x position by an additional minimum radius of a cell */ private void InitHexCell(int x, int z, int index) { HexCell cell = this.hexCells[index] = Instantiate <HexCell>(this.hexCellPrefab); cell.transform.SetParent(this.transform, false); cell.coordinates = HexCoordinates.FromOffset(x, z); cell.transform.localPosition = new Vector3( (x + (z % 2 * 0.5f)) * (HexUtils.MIN_R * 2f), 0f, z * (HexUtils.MAX_R * 1.5f) ); }