// Update is called once per frame void Update() { if (!photonView.IsMine) { GetComponent <Rigidbody>().position = Vector3.MoveTowards(GetComponent <Rigidbody>().position, NetworkPosition, Time.fixedDeltaTime); GetComponent <Rigidbody>().rotation = Quaternion.RotateTowards(GetComponent <Rigidbody>().rotation, NetworkRotation, Time.fixedDeltaTime * 100.0f); /* //Lag compensation * double timeToReachGoal = LagCurrentPacketTime - LagLastPacketTime; * LagCurrentTime += Time.deltaTime; * * //Update remote player * transform.position = Vector3.Lerp(PositionAtLastPacket, LagLatestPos, (float)(LagCurrentTime / timeToReachGoal)); * transform.rotation = Quaternion.Lerp(RotationAtLastPacket, LagLatestRot, (float)(LagCurrentTime / timeToReachGoal));*/ } if (GameStatusScript.getInstance() != null) { Turn = GameStatusScript.getInstance().Turn; if (!PlayersSet && GameStatusScript.getInstance().MatchStatus == MatchStatus.INGAME) { PlayerOne = PhotonNetwork.PlayerList[0]; PlayerTwo = PhotonNetwork.PlayerList[1]; PlayersSet = true; } } /* if (!Input.GetMouseButtonDown(0)) * { * return; * }*/ if (Turn == PlayerType.Player1) { if (PlayerOne.IsLocal) { if (GetComponent <PhotonView>().Owner != PlayerOne) { GetComponent <PhotonView>().RequestOwnership(); } if (StrigerMoving) { StrigerMoveTime += Time.deltaTime; if (StrigerMoveTime > 7) { PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All); if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping()) { StrigerMoveTime = 0; StrigerMoving = false; // Toggle turn here. if (GameSetupScript.GetInstance() != null) { //GameSetupScript.GetInstance().ToggleTurn(); PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient }, SendOptions.SendReliable); GameStatusScript.getInstance().StrigerMoving = false; } } } } } if (Dragging && PlayerOne.IsLocal) { Vector3 rayPoint = getRayPoint(); if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z <= -10 && rayPoint.z >= -14)) { var point = rayPoint; point.y = transform.position.y; point.z = transform.position.z; transform.position = point; StrigerThrow = false; // Toggle Ray cast off here StrigerRayCast.toggleLine(false); } if (rayPoint.z < -13) { StrigerThrow = true; // Toggle Ray cast on here StrigerRayCast.toggleLine(false); DragAngle = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z)); DragLength = Vector3.Distance(transform.position, rayPoint); ThrowAngle = 90 + DragAngle; var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad); var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad); ThrowDirection = new Vector3((float)x, 0, (float)z); Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false); // cast line StrigerRayCast.castLine(transform.position, ThrowDirection); } } } else if (Turn == PlayerType.Player2) { if (PlayerTwo.IsLocal) { if (GetComponent <PhotonView>().Owner != PlayerTwo) { GetComponent <PhotonView>().RequestOwnership(); } if (StrigerMoving) { StrigerMoveTime += Time.deltaTime; if (StrigerMoveTime > 7) { PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All); if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping()) { StrigerMoveTime = 0; StrigerMoving = false; GameStatusScript.getInstance().StrigerMoving = false; // Toggle turn here. if (GameSetupScript.GetInstance() != null) { PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient }, SendOptions.SendReliable); } } } } } if (Dragging && PlayerTwo.IsLocal) { Vector3 rayPoint = getRayPoint(); if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z >= 10 && rayPoint.z <= 12)) { var point = rayPoint; point.y = transform.position.y; point.z = transform.position.z; transform.position = point; StrigerThrow = false; // Toggle Ray cast off here StrigerRayCast.toggleLine(false); } if (rayPoint.z > 12) { StrigerThrow = true; // Toggle Ray cast onn here StrigerRayCast.toggleLine(true); DragAngle = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z)); DragLength = Vector3.Distance(transform.position, rayPoint); ThrowAngle = DragAngle - 90; var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad); var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad); ThrowDirection = new Vector3((float)x, 0, (float)z); Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false); // cast line StrigerRayCast.castLine(transform.position, ThrowDirection); } } } }
// Update is called once per frame void Update() { if (GameStatusScript.getInstance() != null) { Turn = GameStatusScript.getInstance().Turn; } if (Turn == PlayerType.Player1) { if (Dragging) { Vector3 rayPoint = getRayPoint(); if ((rayPoint.x >= -7.5 && rayPoint.x <= 7.5) && (rayPoint.z <= -10 && rayPoint.z >= -14)) { var point = rayPoint; point.y = transform.position.y; point.z = transform.position.z; transform.position = point; StrigerThrow = false; // Toggle Ray cast off here StrigerRayCast.toggleLine(false); } if (rayPoint.z < -13) { StrigerThrow = true; // Toggle Ray cast on here StrigerRayCast.toggleLine(false); DragAngle = AngleBetween(new Vector2(transform.position.x, transform.position.z), new Vector2(rayPoint.x, rayPoint.z)); DragLength = Vector3.Distance(transform.position, rayPoint); ThrowAngle = 90 + DragAngle; var x = 100 * Math.Cos(ThrowAngle * Mathf.Deg2Rad); var z = 100 * Math.Sin(ThrowAngle * Mathf.Deg2Rad); ThrowDirection = new Vector3((float)x, 0, (float)z); Debug.DrawRay(transform.position, ThrowDirection, Color.green, 0.2f, false); // cast line StrigerRayCast.castLine(transform.position, ThrowDirection); } } } if (StrigerMoving) { StrigerMoveTime += Time.deltaTime; if (StrigerMoveTime > 7) { //Unfreeze all y here UnfreezeAllYRPC(); //PhotonView.RPC("UnfreezeAllYRPC", RpcTarget.All); if (CoinController.GetInstance().AllSleeping() && GetComponent <Rigidbody>().IsSleeping()) { StrigerMoveTime = 0; if (GameSetupSingle.GetInstance() != null) { // Toggle turn here GameSetupSingle.GetInstance().ToggleTurn(); //PhotonNetwork.RaiseEvent(RaiseEventCodes.ToggleTurnEvent, null, new RaiseEventOptions() { Receivers = ReceiverGroup.MasterClient }, SendOptions.SendReliable); GameStatusScript.getInstance().StrigerMoving = false; StrigerMoving = false; } } } } }