Hi! I found an open source project on github -> [MatchThree][1]. I have seen, there is a bug. When I started to play this game, I found the mentioned bug: "If we try to switch a bomb and a figure that has a 3 match, then nothing happens. Neither the bomb does not work, nor the 3 identical figures will disappear" and got this message:
InvalidCastException: Cannot cast from source type to destination type.
Board+c__Iterator0.MoveNext () (at Assets/Scripts/Board/Board.cs:272)
UnityEngine.SetupCoroutine.InvokeMoveNext (IEnumerator enumerator, IntPtr returnValueAddress) (at C:/buildslave/unity/build/Runtime/Export/Coroutines.cs:17)
Can you help me to find the solution?
IEnumerator SwitchTilesRoutine(Tile clickedTile, Tile targetTile)
{
if (_playerInputEnabled && !GameManager.Instance.IsGameOver)
{
GamePiece clickedPiece = AllPieces[clickedTile.IndexX, clickedTile.IndexY];
GamePiece targetPiece = AllPieces[targetTile.IndexX, targetTile.IndexY];
if (targetPiece != null && clickedPiece != null)
{
clickedPiece.Move(targetTile.IndexX, targetTile.IndexY, _swapTime);
targetPiece.Move(clickedTile.IndexX, clickedTile.IndexY, _swapTime);
yield return new WaitForSeconds(_swapTime);
List clickedPieceMatches = new List();
List targetPieceMatches = new List();
List clickedPieceBombed = new List();
List targetPieceBombed = new List();
if (clickedPiece.GetType() == typeof(Bomb))
{
Bomb clickedBomb = (Bomb)clickedPiece;
if (clickedBomb.BombType == BombType.Color)
{
clickedBomb.MatchValue = targetPiece.MatchValue;
}
clickedPieceBombed = MatchFinder.FindBombedPieces(AllPieces, clickedBomb);
}
else
clickedPieceMatches = MatchFinder.FindMatchesAt(AllPieces, clickedTile.IndexX, clickedTile.IndexY);
if (targetPiece.GetType() == typeof(Bomb))
{
Bomb targetBomb = (Bomb)clickedPiece; //the problem
if (targetBomb.BombType == BombType.Color)
{
targetBomb.MatchValue = clickedPiece.MatchValue;
}
clickedPieceBombed = MatchFinder.FindBombedPieces(AllPieces, targetBomb);
}
else
targetPieceMatches = MatchFinder.FindMatchesAt(AllPieces, targetTile.IndexX, targetTile.IndexY);
if (targetPieceMatches.Count == 0 && clickedPieceMatches.Count == 0&& targetPieceBombed.Count == 0 && clickedPieceBombed.Count == 0)
{
clickedPiece.Move(clickedTile.IndexX, clickedTile.IndexY, _swapTime);
targetPiece.Move(targetTile.IndexX, targetTile.IndexY, _swapTime);
}
else
{
if (GameManager.Instance != null)
{
GameManager.Instance.UpdateMoves();
}
Vector2 swipeDirection = new Vector2(targetTile.IndexX - clickedTile.IndexX, targetTile.IndexY - clickedTile.IndexY);
_clickedTileBomb = DropBomb(clickedTile.IndexX, clickedTile.IndexY, swipeDirection, clickedPieceMatches);
_targetTileBomb = DropBomb(targetTile.IndexX, targetTile.IndexY, swipeDirection, targetPieceMatches);
ClearAndRefillBoard(clickedPieceMatches.Union(targetPieceMatches).ToList()
.Union(targetPieceBombed).ToList().Union(clickedPieceBombed).ToList());
}
}
}
}
[1]: https://github.com/NikolaBerovic/MatchThree_Unity
↧