private bool CheckForTile(Touch touch, out TouchableTile tile) { bool haveTile = false; tile = null; touchOrigin = touch.position; touchPositionText.text = "Touch position: " + touchOrigin.x + ", " + touchOrigin.y; Vector3 touchTarget = Camera.main.ScreenToWorldPoint(touchOrigin); // map from world to game position int touchX = (int)Mathf.Round(touchTarget.x); int touchY = (int)Mathf.Round(touchTarget.y); touchTargetText.text = "Touch Target: " + touchX + ", " + touchY; // Check for a tile at this position and touch it Vector3 location = new Vector3(touchX, touchY, 0); if (tilePositions.TryGetValue(location, out tile)) { touchPositionText.text = "Got it"; haveTile = true; } return(haveTile); }
// Sets up the board void BoardSetup() { Debug.Log("BoardManager boardSetup for rows " + rows + ", columns " + columns); boardHolder = new GameObject("Board").transform; // Build the outer wall and floor tiles for (int x = -1; x < columns + 1; x++) { for (int y = -1; y < rows + 1; y++) { TouchableTile toInstantiate = floorTiles[floorTiles.Length - 1]; // Check for outer walls if (x == -1 || x == columns || y == -1 || y == rows) { // Replace object with outer wall object toInstantiate = outerWallTiles[Random.Range(0, outerWallTiles.Length)]; } // Quaternion.identity means no rotation Vector3 objectTransform = new Vector3(x, y, 0f); TouchableTile tileInstance = Instantiate(toInstantiate, objectTransform, Quaternion.identity); tileInstance.transform.SetParent(boardHolder); // Store the object in the game dictionary tilePositions.Add(objectTransform, tileInstance); } } }