//Gaint Update private void Update() { if (isGameOver) { return; } Vector3 rayPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Input.GetMouseButtonDown(0)) { CellView cell = GetCell(rayPosition); if (cell != null) { if (cell.HasValue() && !cell.IsCompleted) { currentCell = cell; startCell = cell; startCellValue = currentCell.CellValue; if (!_path.ContainsKey(startCellValue)) { _path.Add(startCellValue, new List <CellView>()); } else if (_path.ContainsKey(StartCellValue) && _path[startCellValue].Count > 0) { RemovePath(StartCellValue); } _path[startCellValue].Add(currentCell); currentLineColor = currentCell.GetColor(); } else if (!cell.IsCompleted && cell.CellValue != 0) { currentCell = cell; startCell = _path[cell.CellValue][0]; startCellValue = _path[cell.CellValue][0].CellValue; currentLineColor = _path[cell.CellValue][0].GetColor(); _path[startCellValue].Add(currentCell); } else if (cell.IsCompleted) { RemovePath(cell.CellValue); } } } else if (Input.GetMouseButton(0)) { if (currentCell != null) { CellView cell = GetCell(rayPosition); if (cell != null && cell.Index != currentCell.Index) { if (currentCell.AddLine(cell)) { currentCell = cell; _path[startCellValue].Add(currentCell); if (currentCell.IsCompleted) { currentCell = null; startCell.IsCompleted = true; } } else { RemovePath(StartCellValue); currentCell = null; } } } } else if (Input.GetMouseButtonUp(0)) { if (currentCell != null) { if (currentCell.HasValue() && currentCell.IsCompleted) { currentCell = null; startCell = null; } else { RemovePath(StartCellValue); currentCell = null; } } CheckForGameOver(); } }