public void deselectPiece() { if (selected != null) { DragPiece selectedData = selected.GetComponent <DragPiece>(); if (selectedData.inStack) { selectedData.crushWall(); } selected.GetComponent <MeshRenderer>().material = materialOfSelected; selected = null; } }
public void selectPiece(GameObject piece) { if (selected == piece) { DragPiece selectedData = selected.GetComponent <DragPiece>(); if (selectedData.inStack && !selectedData.isCap) { if (selectedData.isWall) { selectedData.crushWall(); deselectPiece(); } else { selectedData.makeWall(); } } else { deselectPiece(); } } else if (selected == null) { if (piece.GetComponent <DragPiece>().isMovable) { selected = piece; materialOfSelected = selected.GetComponent <MeshRenderer>().material; selected.GetComponent <MeshRenderer>().material = selectedMaterial; } } else { moveSelectedPieceTo(piece); } }
bool isEligibleTarget(GameObject toHere) { Vector3 targetPos = toHere.transform.position; Vector3 selectedPos = selected.transform.position; //Debug.Log("checking eligiblity"); if (toHere.tag != "boardSquare") { //check if you are moving onto another piece DragPiece toHereData = toHere.GetComponent <DragPiece>(); if (toHereData.isCap) { setErrorText("You cannot move onto a Cap Stone"); return(false); } else if (toHereData.isWall) //cannot move onto a wall { if (selected.GetComponent <DragPiece>().isCap) { toHereData.crushWall(); return(true); } setErrorText("You cannot move onto a wall"); return(false); } } if (selected.GetComponent <DragPiece>().inStack) { Debug.Log("selected is from stack"); if (toHere.tag != "boardSquare") { setErrorText("Moving a piece from stack on top of another piece is not allowed"); return(false); //a move from the stack to another piece is not allowed } return(true); } else if (targetPos.x == selectedPos.x) { if (targetPos.z == selectedPos.z) //the target and the selected are in the same position { setErrorText("Cannot move to the same position"); return(false); } else if (currentDirection == direction.horizontal) { setErrorText("You can only move horizontally"); return(false); } else if (targetPos.z == selectedPos.z + 1.0f || targetPos.z == selectedPos.z - 1.0f) { switch (currentDirectionSign) { case directionSign.neither: currentDirectionSign = (targetPos.z == selectedPos.z + 1.0f) ? directionSign.positive : directionSign.negative; currentDirection = direction.vertical; return(true); case directionSign.negative: return(targetPos.z == selectedPos.z - 1.0f); case directionSign.positive: return(targetPos.z == selectedPos.z + 1.0f); } } setErrorText("You can only move one square at a time"); return(false); } else if (targetPos.z == selectedPos.z) { if (currentDirection == direction.vertical) { setErrorText("You can only move vertically"); return(false); } else if (targetPos.x == selectedPos.x + 1.0f || targetPos.x == selectedPos.x - 1.0f) { switch (currentDirectionSign) { case directionSign.neither: currentDirectionSign = (targetPos.x == selectedPos.x + 1.0f) ? directionSign.positive : directionSign.negative; currentDirection = direction.horizontal; return(true); case directionSign.negative: return(targetPos.x == selectedPos.x - 1.0f); case directionSign.positive: return(targetPos.x == selectedPos.x + 1.0f); } } setErrorText("You can only move one square at a time"); return(false); } setErrorText("You cannot move diagonally"); return(false); }