public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) { if (stream.IsWriting) { // Position Vector3 _pos = transform.position; stream.SendNext(_pos.x); stream.SendNext(_pos.z); // Rotation stream.SendNext(transform.rotation.eulerAngles.y); // Combat stream.SendNext(bulletsFired); bulletsFired = 0; } else { if (PlayerManager.LocalPlayerPrefab != null && networkSimulation == null) { networkSimulation = PlayerManager.LocalPlayerPrefab.GetComponentInChildren <NetworkSimulation>(); } // Position float posX = (float)stream.ReceiveNext(); float posZ = (float)stream.ReceiveNext(); // Rotation float rotationY = (float)stream.ReceiveNext(); // Combat bulletsFired += (byte)stream.ReceiveNext(); if (networkSimulation != null) { float _packetLoss = networkSimulation.GetPacketLossPercentage() / 100.0f; float _rand = randomNumbers[randomIndex]; randomIndex = (randomIndex + 1) % randomNumbers.Length; if ((1.0f - _packetLoss) > _rand) { previousPosition = transform.position; newPosition = new Vector3(posX, transform.position.y, posZ); previousRotation = transform.rotation; newRotation = Quaternion.Euler(previousRotation.x, rotationY, previousRotation.z); timeSinceLastUpdate = 0; } } } }