void Update() { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); // Changes tile and restart button sprite when mouse pressed if (Input.GetMouseButton(0)) { if (isFinished()) { return; } if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <TileClass>()) { TileClass tile = hit.transform.GetComponent <TileClass>(); if (!tile.isCovered() || tile.Flag) { return; } hitRecord.Add(tile); tile.SprRen.sprite = tile.ClickedTileTexture; buttons.restartButton.sprite = buttons.pressingButtonTexture; } } } // Changes tile and restart button sprite when mouse released if (Input.GetMouseButtonUp(0)) { if (hitRecord.Count > 0) { hitRecord[hitRecord.Count - 1].UncoverTile(); } hitRecord.Clear(); if (isFinished()) { buttons.restartButton.sprite = buttons.deadButtonTexture; } else { buttons.restartButton.sprite = buttons.idleButtonTexture; } } // Switch tile flag on/off if (Input.GetMouseButtonDown(1)) { if (isFinished()) { return; } if (Physics.Raycast(ray, out hit)) { if (hit.transform.GetComponent <TileClass>()) { TileClass tile = hit.transform.GetComponent <TileClass>(); if (!tile.isCovered()) { return; } tile.Flag = !tile.Flag; if (tile.Flag) { tile.ChangeTexture(0); } else { tile.ChangeTexture(9); } } } } if (win) { buttons.restartButton.sprite = buttons.winButtonTexture; } }