void OnTileClicked(SpriteTile sender) { if (_currentTile != null) { if (sender == _currentTile) { // Deselect if we click the same tile again SetCurrentTile(null); } else if (sender.Matches(_currentTile)) { int turns = int.MaxValue; // Temporarily set the target node to be walkable before pathfinding since AStar needs to be able to walk onto the node to find it. float oldWeight = sender.gridNode.pathfindingWeight; sender.gridNode.pathfindingWeight = 1; IAStarNode[] path = AStar.CalculatePath(_currentTile.gridNode, sender.gridNode, out turns); sender.gridNode.pathfindingWeight = oldWeight; if (turns <= GameSettings.maxPathfindingTurns) { // If it's a valid match spawn a MatchAnimation and play it _currentTile.gameObject.AddComponent <MatchAnimation>().Play(_currentTile, sender, path); SetCurrentTile(null); } else { // If the path has too many turns simply select the tile instead SetCurrentTile(sender); } } else { // Tile's don't match, select the new one SetCurrentTile(sender); } } else { // We don't have a selected tile yet, select the new one SetCurrentTile(sender); } }