public void SendRemovePiece(PlayerPiece p) { using (DarkRiftWriter writer = DarkRiftWriter.Create()) { //write the piece ID and its updated x and y coordinates writer.Write(p.GetComponent <NetworkCheckersPiece>().id); using (Message message = Message.Create(NetworkTags.InGame.DEFEAT, writer)) clientReference.SendMessage(message, SendMode.Unreliable); Player.instance.canMakeMove = false; } }
public void AbsorbePiece() { if (absorbedPiece != null) { absorbedPiece.transform.SetParent(alienShipRay); absorbedPiece.transform.localPosition = Vector3.zero; absorbedPiece.state = PieceState.BeingDestroyed; absorbedPiece.disableRigidBody = true; Destroy(absorbedPiece.GetComponent <Rigidbody>()); } }
public void AttachPieceToChopsticks() { if (piece == null) { return; } piece.transform.SetParent(pieceParent); piece.transform.localPosition = Vector3.zero; piece.transform.rotation = Quaternion.identity; piece.disableRigidBody = true; piece.state = PieceState.BeingDestroyed; Destroy(piece.GetComponent <Rigidbody>()); }
IEnumerator PlayingRoutine() { turnIndicator.SetActive(true); //CALL FROM TURNS Debug.Log("playing"); while (playing) { if (currentPlayingPiece == null) { dropBox.gameObject.SetActive(false); dropBox.enabled = false; if (Input.GetMouseButtonUp(0)) { Debug.Log("click2" + this.gameObject); LayerMask layerMaskPiece = LayerMask.GetMask("Pieces"); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMaskPiece)) { Debug.Log("piece"); if (!IsPointerOverUIObject()) { Debug.Log("uiCheck"); controller.manager.PlaySound(controller.manager.clickClip); PlayerPiece piece = hit.collider.GetComponent <PlayerPiece>(); PlayerPiece playingPieceClone = Instantiate(piece, Input.mousePosition, Quaternion.identity); playingPieceClone.name = playerID + "piece" + playingPieceClone.value; playingPieceClone.gameObject.layer = 1; piece.GetComponent <BoxCollider>().enabled = false; piece.GetComponent <SpriteRenderer>().enabled = false; currentPlayingPiece = playingPieceClone; dropBox.gameObject.SetActive(true); dropBox.enabled = true; } } } } else { if (!Input.GetMouseButtonUp(1)) { Vector3 temp = Input.mousePosition; temp.z = 10f; currentPlayingPiece.transform.position = Camera.main.ScreenToWorldPoint(temp); LayerMask layerMaskCell = LayerMask.GetMask("Cell"); LayerMask layermaskPieceAvoid = LayerMask.GetMask("Pieces"); LayerMask layerDropBox = LayerMask.GetMask("Drop"); layermaskPieceAvoid = ~layermaskPieceAvoid; if (Input.GetMouseButtonUp(0)) { Debug.Log("click"); RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); //if(Physics.Raycast(ray, out hit, Mathf.Infinity, layerDropBox)) if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerDropBox)) { dropBox.gameObject.SetActive(false); dropBox.enabled = false; controller.manager.PlaySound(controller.manager.pieceClip); Debug.Log("Droped piece " + hit.transform.name); foreach (PlayerPiece piece in this.GetComponentsInChildren <PlayerPiece>()) { piece.GetComponent <BoxCollider>().enabled = true; piece.GetComponent <SpriteRenderer>().enabled = true; } Destroy(currentPlayingPiece.gameObject); } if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMaskCell)) { if (!IsPointerOverUIObject()) { Cell playingCell = hit.collider.GetComponent <Cell>(); Cursor.SetCursor(null, Vector2.zero, CursorMode.Auto); if (!currentPlayingPiece.blocker) { if (controller.manager.freePositions.Contains(playingCell)) { if (CheckLastPosition(lastPositionPlayed, playingCell)) { controller.manager.PlaySound(controller.manager.pieceClip); Cell hitCell = hit.transform.GetComponent <Cell>(); hitCell.CallPieceDATA(currentPlayingPiece); lastPositionPlayed = hitCell; listOfPlayedPositions.Add(lastPositionPlayed); controller.manager.usedPositions.Add(lastPositionPlayed); controller.manager.freePositions.Remove(playingCell); //END OF ROUND controller.turnManager.SendDiceMove(lastPositionPlayed); //SendMessage move to turn manager Destroy(currentPlayingPiece.gameObject); StartCoroutine(MarkerMovement(hitCell)); //turns -= 1; foreach (PlayerPiece piece in this.GetComponentsInChildren <PlayerPiece>()) { piece.GetComponent <SpriteRenderer>().enabled = true; } controller.localPlayerInfo.dice -= 1; controller.localPlayerInfo.diceCounter.text = controller.localPlayerInfo.dice.ToString(); ExitGames.Client.Photon.Hashtable newHash = PhotonNetwork.LocalPlayer.CustomProperties; newHash["dice"] = dice - 1; PhotonNetwork.LocalPlayer.SetCustomProperties(newHash); Debug.Log("played piece"); playing = false; } else { controller.manager.PlaySound(controller.manager.errorClip); StartCoroutine(VibrateMarkerPiece()); } } else { controller.manager.PlaySound(controller.manager.errorClip); } } else if (controller.manager.freePositions.Contains(playingCell)) { usedBlocker = true; controller.manager.PlaySound(controller.manager.pieceClip); Cell hitCell = hit.transform.GetComponent <Cell>(); hitCell.CallPieceDATA(currentPlayingPiece); listOfPlayedPositions.Add(hitCell); controller.manager.usedPositions.Add(hitCell); controller.manager.freePositions.Remove(playingCell); //Cell BlockerCell = hitCell; controller.turnManager.SendBlockerMove(hitCell); //Send moves to turn manager Destroy(currentPlayingPiece.gameObject); blocker.SetActive(false); //foreach (PlayerPiece piece in this.GetComponentsInChildren<PlayerPiece>()) //{ // if (piece.blocker) // { // piece.gameObject.SetActive(false); // //Destroy(piece.gameObject); // } //} } } } } } else { dropBox.gameObject.SetActive(false); dropBox.enabled = false; controller.manager.PlaySound(controller.manager.pieceClip); Debug.Log("Canceled droped"); foreach (PlayerPiece piece in this.GetComponentsInChildren <PlayerPiece>()) { piece.GetComponent <BoxCollider>().enabled = true; piece.GetComponent <SpriteRenderer>().enabled = true; } Destroy(currentPlayingPiece.gameObject); } } yield return(null); } Debug.Log("end of turn"); dropBox.gameObject.SetActive(false); dropBox.enabled = false; running = false; }