void CreateCell(int x, int z, int i) { Vector3 position; position.x = x; position.y = 0f; position.z = z; SquareCell cell = cells[i] = Instantiate <SquareCell>(cellPrefab); cell.transform.localPosition = position; if (x > 0) { cell.SetNeighbor(GridDirection.W, cells[i - 1]); } if (z > 0) { cell.SetNeighbor(GridDirection.S, cells[i - cellCountX]); } if (z > 0 && x > 0) { cell.SetNeighbor(GridDirection.SW, cells[i - cellCountX - 1]); } if (z > 0 && x < cellCountX - 1) { cell.SetNeighbor(GridDirection.SE, cells[i - cellCountX + 1]); } cell.coordinates = GridCoordinates.FromOffsetCoordinates(x, z); if (heightmap == null) { cell.GridElevations = GridElevations.GetVertexHeights(position, seed); } else { cell.GridElevations = GridElevations.GetVertexHeightsFromHeightmap(position, heightmap); } // start off with grass everywhere cell.Tile = gridMaterials[0].GetClone; if (cell.CentreElevation < 7) // basic treeline cut-off { cell.PlantLevel = UnityEngine.Random.Range(0, 100) - 95; } AddCellToChunk(x, z, cell); }