private void MovePiece() { Piece piece = gameManager.pickedPiece.GetComponent <Piece>(); if (piece.type == Piece.PieceType.grey) { MoveGreyPieces(piece); } else { if (piece.type == Piece.PieceType.green && piece.carry) { foreach (GameObject friendlyPiece in piece.friendlyPieces) { if (friendlyPiece != piece.gameObject && (Vector2)friendlyPiece.transform.position == (Vector2)piece.transform.position) { friendlyPiece.transform.position = new Vector3(transform.position.x, transform.position.y, friendlyPiece.GetComponent <Piece>().z); break; } } } piece.direction = new Vector2(System.Math.Sign(transform.position.x - piece.transform.position.x), System.Math.Sign(transform.position.y - piece.transform.position.y)); piece.transform.position = new Vector3(transform.position.x, transform.position.y, piece.z); if (piece.type == Piece.PieceType.green) { piece.AOE(1); } if (piece.type == Piece.PieceType.brown) { bool onPiece = false; foreach (GameObject friendlyPiece in piece.friendlyPieces) { if ((Vector2)piece.transform.position == (Vector2)friendlyPiece.transform.position && piece.gameObject != friendlyPiece) { onPiece = true; friendlyPiece.GetComponent <Piece>().invincible = true; piece.z = -1.75f; piece.transform.position = new Vector3(piece.transform.position.x, piece.transform.position.y, piece.z); } else { if (friendlyPiece.GetComponent <Piece>().killCount != 2) { friendlyPiece.GetComponent <Piece>().invincible = false; } } } piece.invincible = onPiece; if (!piece.invincible) { piece.z = -1f; piece.transform.position = new Vector3(piece.transform.position.x, piece.transform.position.y, piece.z); } Debug.Log(piece.invincible); } if (!(piece.type == Piece.PieceType.blue && piece.killCount != 0)) { gameManager.moveCount++; } } }