//Create a tile from the prefab and set the size and properties TileLogic CreateTile(float tileScale, int row, int col, float tileSize) { GameObject tile = Instantiate(tilePrefab, gridParent.transform, false); TileLogic tileLogic = tile.GetComponent <TileLogic>(); if (tileLogic == null) { return(null); } tileLogic.ScaleTile(tileScale, tileSize, true); float a = row - (int)(crossword.size.rows / 2) + ((crossword.size.rows % 2 + 1) % 2) * .5f; float b = col - (int)(crossword.size.cols / 2) + ((crossword.size.cols % 2 + 1) % 2) * .5f; tile.transform.localPosition = new Vector2(b * tileSize, -(a * tileSize)); int index = IndexForRowAndCol(row, col); string _downAnswer = GetClueOrAnswer(false, false, index); string _downClue = GetClueOrAnswer(true, false, index); string _acrossAnswer = GetClueOrAnswer(false, true, index); string _acrossClue = GetClueOrAnswer(true, true, index); tileLogic.SetupTile(crossword.grid[index], crossword.gridnums[index], _acrossClue, _acrossAnswer, _downClue, _downAnswer, IndexForRowAndCol(row, col)); return(tileLogic); }
//Create a tile from the prefab and set the size and properties TileLogic CreateTile(float tileScale, int row, int col, float tileSize, int[] scoreMults) { GameObject tile = Instantiate(tilePrefab, gridParent.transform, false); TileLogic tileLogic = tile.GetComponent <TileLogic>(); if (tileLogic == null) { return(null); } int index = IndexForRowAndCol(row, col); if (index < scoreMults.Length) { tileLogic.SetScoreMult(scoreMults[index]); // set the randomly generated score multiplier for the tile } tileLogic.ScaleTile(tileScale, tileSize, true); float a = row - (int)(crossword.size.rows / 2) + ((crossword.size.rows % 2 + 1) % 2) * .5f; //set the position of the tile in the grid based on the row and col float b = col - (int)(crossword.size.cols / 2) + ((crossword.size.cols % 2 + 1) % 2) * .5f; tile.transform.localPosition = new Vector2(b * tileSize, -(a * tileSize)); string downAnswer = GetClueOrAnswer(false, false, index); string downClue = GetClueOrAnswer(true, false, index); string acrossAnswer = GetClueOrAnswer(false, true, index); string acrossClue = GetClueOrAnswer(true, true, index); tileLogic.SetupTile(crossword.grid[index], crossword.gridnums[index], acrossClue, acrossAnswer, downClue, downAnswer, index); return(tileLogic); }