private void Update() { if (Input.GetMouseButtonDown(0)) { Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y); //int layerMask = 1 << 8; int layerMask = LayerMask.GetMask("PuzzlePiece"); // Does the ray intersect any objects which are in the PuzzlePiece layer? if (Physics2D.Raycast(mousePos2D, Vector3.forward, Mathf.Infinity, layerMask)) { RaycastHit2D hit = Physics2D.Raycast(mousePos2D, Vector2.zero, Mathf.Infinity, layerMask); // Process the click here - get the object that was clicked and then determine if it can be swapped with the empty block if (hit.collider != null) { //Block clickedBlock = new Block(Convert.ToInt32(hit.collider.gameObject.name), hit.collider.gameObject); Block clickedBlock = LevelController.gameplayBlockList.Where(i => i.BlockObject.name == hit.collider.gameObject.name).FirstOrDefault(); BlockSwapper.SwapBlocks(LevelController.emptyBlock, clickedBlock); } } } }
public static void ScrambleBlocks(LevelController levelController) { int blockFactor = levelController.blockFactor; int blockSwapNumber = 0; System.Random r = new System.Random(); for (int i = 0; i < levelController.maxBlocks; i++) { // Get a random block number to swap with blockSwapNumber = r.Next(levelController.maxBlocks); BlockSwapper.SwapBlocks(LevelController.gameplayBlockList[i], LevelController.gameplayBlockList[blockSwapNumber]); } levelController.SetNewGame(false); }