- Home /
if statement works when swapped with other if statement
Hi, I have a problem with if statement. Im making a match 3 game and when the color bomb is switched with a row, column or adjacent bomb, it searches for all the pieces with the same color and then changes them to bombs. It works fine, but only for the first if statemnet -is it row or column bomb. for second if statement (is it adjacent bomb?) it generates bombs but they lose component called bomb and dont explode. When I change the order of the if statements and "is it adjacent bomb" statement is first then it works fine for adjacent bombs, but column or row bombs dont explode. So just changing the order of the if statement chages the behavior of the game... What might be the reason of this? I made bombs not to explode instantly and when I made a match with these bombs in second move they exploded normally. So they just didnt explode during the swap with color bomb.
if (IsColorBomb(clickedPiece) && !IsColorBomb(targetPiece))
{
if (IsRowBomb(targetPiece) || IsColumnBomb(targetPiece))
{
clickedPiece.matchValue = targetPiece.matchValue;
colorMatches = FindAllMatchValue(clickedPiece.matchValue);
int randomBomb;
foreach (GamePiece gamePiece in colorMatches)
{
randomBomb = UnityEngine.Random.Range(0, 2);
GameObject bomb = DropCertainBomb(gamePiece.xIndex, gamePiece.yIndex, clickedPiece.matchValue, randomBomb);
ClearPieceAt(gamePiece.xIndex, gamePiece.yIndex);
ActivateBomb(bomb);
GamePiece piece = bomb.GetComponent<GamePiece>();
newBombs.Add(piece);
if (m_particleManager != null)
{
m_particleManager.ColorPickedFXAt(piece.xIndex, piece.yIndex, 0, 0f);
}
}
}
if (IsAdjacentBomb(targetPiece))
{
clickedPiece.matchValue = targetPiece.matchValue;
colorMatches = FindAllMatchValue(clickedPiece.matchValue);
int randomBomb = 2;
foreach (GamePiece gamePiece in colorMatches)
{
GameObject bomb = DropCertainBomb(gamePiece.xIndex, gamePiece.yIndex, clickedPiece.matchValue, randomBomb);
ClearPieceAt(gamePiece.xIndex, gamePiece.yIndex);
ActivateBomb(bomb);
GamePiece piece = bomb.GetComponent<GamePiece>();
newBombs.Add(piece);
if (m_particleManager != null)
{
m_particleManager.ColorPickedFXAt(piece.xIndex, piece.yIndex, 0, 0f);
}
}
}
else
{
clickedPiece.matchValue = targetPiece.matchValue;
matchValues.Add(clickedPiece.matchValue);
colorMatches = FindAllMatchValue(clickedPiece.matchValue);
}
}