void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } if (Quaternion.Angle(woodenBoard.transform.rotation, desiredRotation) > 0.1f) { elaspedTime += Time.deltaTime * rotationSpeed; woodenBoard.transform.rotation = Quaternion.Lerp(woodenBoard.transform.rotation, desiredRotation, elaspedTime); } if (needToUpdateNbStep) { needToUpdateNbStep = false; sideTrayAnimator.SetTrigger("Close"); nbStep.text = resolutionInformation[0].Split(':')[1].ToString().Trim(); complexitySize.text = resolutionInformation[1].Split(':')[1].ToString().Trim(); complexityTime.text = resolutionInformation[2].Split(':')[1].ToString().Trim(); elapsedTime.text = resolutionInformation[3].Split(':')[1].ToString().Trim(); } if (client.errorMessage != null) { uiManager.DisplayError(client.errorMessage); client.errorMessage = null; sideTrayAnimator.SetTrigger("Close"); ResetSolution(); } if (!inSettings && canMove) { if (Input.GetKeyDown(KeyCode.RightArrow)) { boardManager.AddMovements(BoardManager.MoveDirection.Right); ResetSolution(); } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { boardManager.AddMovements(BoardManager.MoveDirection.Left); ResetSolution(); } else if (Input.GetKeyDown(KeyCode.UpArrow)) { boardManager.AddMovements(BoardManager.MoveDirection.Up); ResetSolution(); } else if (Input.GetKeyDown(KeyCode.DownArrow)) { boardManager.AddMovements(BoardManager.MoveDirection.Down); ResetSolution(); } } if (Input.GetMouseButtonDown(0)) { RaycastHit hit; Ray ray = cam.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit)) { if (hit.collider.CompareTag("Cell") && playCoroutine == null) { if (swapFirstCell == null) { swapFirstCell = hit.collider.GetComponent <Cell>(); if (swapFirstCell.value == 0) { swapFirstCell = null; } else { swapFirstCell.GetComponent <MeshRenderer>().material = swapCellSelectedMaterial; } } else { swapSecondCell = hit.collider.GetComponent <Cell>(); if (swapSecondCell.value != 0) { swapFirstCell.GetComponent <MeshRenderer>().material = swapCellOriginalMaterial; Vector3 tmpPos = swapSecondCell.transform.position; swapSecondCell.transform.position = swapFirstCell.transform.position; swapFirstCell.transform.position = tmpPos; int iFirstCell = -1, iSecondCell = -1; int jFirstCell = -1, jSecondCell = -1; for (int i = 0; i < boardManager.N; i++) { if (jFirstCell == -1) { iFirstCell = i; jFirstCell = boardManager.values[i].FindIndex(o => o == swapFirstCell.value); } if (jSecondCell == -1) { iSecondCell = i; jSecondCell = boardManager.values[i].FindIndex(o => o == swapSecondCell.value); } } if (jFirstCell != -1 && jSecondCell != -1) { int tmp = boardManager.values[iFirstCell][jFirstCell]; boardManager.values[iFirstCell][jFirstCell] = boardManager.values[iSecondCell][jSecondCell]; boardManager.values[iSecondCell][jSecondCell] = tmp; } swapFirstCell = null; swapSecondCell = null; boardManager.GetClosestCells(); } else { swapSecondCell = null; } } } } } }