void GenerateGridWithCells() { for (int i = 0; i < _columnCount; i++) { for (int j = 0; j < _rowCount; j++) { GameObject cellObj = Instantiate(_cellPrefab, _grid); CellBase cell = cellObj.GetComponent <CellBase>(); // set size of cell according to terrain size cell.CellSize = _currentCellSize = new Vector2(_terrain.terrainData.size.x / _columnCount, _terrain.terrainData.size.z / _rowCount); cell.Index = new Vector2Int(i, j); cell.SetPositionAndSize(); _cells.Add(cellObj); } } }