/// <summary> /// Moves game piece to new tile /// </summary> /// <param name="gamePiece">Selected game piece</param> /// <param name="tile">New tile</param> public void MoveGamePiece(GameObject gamePiece, Tile tile) { GamePiece gamePieceData = gamePiece.GetComponent <GamePiece>(); gamePieceData.GetGamePieceParentTile().GetComponent <Tile>().ChangePieceOnTile(null); tile.ChangePieceOnTile(gamePiece); gamePieceData.ChangeParentTile(tile); gamePiece.transform.position = tile.transform.position; gamePiece.transform.parent = tile.transform; }
/// <summary> /// Places one piece to position with certain color. /// </summary> /// <param name="tile">Piece's position</param> /// <param name="pieceColor">Piece's color</param> public void PlacePiece(Tile tile, Material pieceMaterial, string pieceName, int teamNumber) { GameObject newGamePiece = Instantiate(gamepieceObject, tile.transform); MeshFilter mesh = newGamePiece.GetComponentInChildren <MeshFilter>(); GamePiece newGamePieceData = newGamePiece.GetComponent <GamePiece>(); switch (pieceName) { case "Pawn": Pawn pawn = newGamePiece.AddComponent(typeof(Pawn)) as Pawn; mesh.mesh = pieceModels[0]; break; case "Rook": Rook rook = newGamePiece.AddComponent(typeof(Rook)) as Rook; mesh.mesh = pieceModels[1]; break; case "Knight": Knight knight = newGamePiece.AddComponent(typeof(Knight)) as Knight; mesh.mesh = pieceModels[2]; break; case "Bishop": Bishop bishop = newGamePiece.AddComponent(typeof(Bishop)) as Bishop; mesh.mesh = pieceModels[3]; break; case "Queen": Queen queen = newGamePiece.AddComponent(typeof(Queen)) as Queen; mesh.mesh = pieceModels[4]; break; case "King": King king = newGamePiece.AddComponent(typeof(King)) as King; mesh.mesh = pieceModels[5]; break; default: Debug.Log("Error: no such thing as " + pieceName); break; } tile.ChangePieceOnTile(newGamePiece); newGamePieceData.ChangeParentTile(tile); newGamePieceData.ChangeTeamNumber(teamNumber); newGamePiece.GetComponentInChildren <MeshRenderer>().material = pieceMaterial; newGamePiece.name = pieceName; }