public void Click(MatchingTile tile) { if (paused) { return; } if (tile == null) { return; } if (currentSelection == null) { currentSelection = tile; } else { currentSelection2 = tile; paused = true; if (currentSelection.tile == currentSelection2.tile) { StartCoroutine(SucessCoroutine()); } else { StartCoroutine(RetryCoroutine()); } } tile.FlipUp(); }
private void SetupTiles() { List <Tile> _tiles = new List <Tile>(tiles); List <MatchingTile> _matchingTiles = new List <MatchingTile>(matchingTiles); while (_tiles.Count > 0) { int _index = Random.Range(0, _tiles.Count); Tile _tile = _tiles[_index]; _tiles.Remove(_tile); if (_matchingTiles.Count > 0) { int _index2 = Random.Range(0, _matchingTiles.Count); MatchingTile _matchingtile1 = _matchingTiles[_index2]; _matchingtile1.SetTile(_tile, this); _matchingTiles.Remove(_matchingtile1); } if (_matchingTiles.Count > 0) { int _index3 = Random.Range(0, _matchingTiles.Count); MatchingTile _matchingtile2 = _matchingTiles[_index3]; _matchingtile2.SetTile(_tile, this); _matchingTiles.Remove(_matchingtile2); } } }
private IEnumerator SucessCoroutine() { yield return(new WaitForSeconds(resetDelay)); if (currentSelection != null) { currentSelection.FlipUp(); } if (currentSelection2 != null) { currentSelection2.FlipUp(); } correctTiles.Add(currentSelection); correctTiles.Add(currentSelection2); if (correctTiles.Count >= matchingTiles.Count) { puzzleSuccessEvent.Invoke(); StopGame(); } currentSelection = null; currentSelection2 = null; paused = false; }
private void ResetGame() { currentSelection = null; currentSelection2 = null; correctTiles.Clear(); foreach (MatchingTile _tile in matchingTiles) { _tile.ClearTile(); _tile.FlipDown(); } }
private IEnumerator RetryCoroutine() { yield return(new WaitForSeconds(resetDelay)); if (currentSelection != null) { currentSelection.FlipDown(); } if (currentSelection2 != null) { currentSelection2.FlipDown(); } currentSelection = null; currentSelection2 = null; paused = false; }