Im having a hard time synchronizing weapons for my character. I have a GameObject “WeaponAttacher” that holds the position and rotation for the weapon, it is a child of the hand bone. When i equip a weapon i set the weapon gameobjects rotation and position to the attachers and i parent it to the attacher gameobject. I dont get what i need to synchronize for other clients to see.
WeaponSlot = (GameObject)PhotonNetwork.Instantiate (name, WeaponAttacher.position, WeaponAttacher.rotation, 0);
WeaponSlot .GetComponent<DroppedItem> ().item = itemDatabase.getNewItem(id);
WeaponSlot .transform.parent = WeaponAttacher;
EquippedWeaponSlot = WeaponSlot ;
The EquippedWeaponSlot is just a reference to the currently equipped weapon, as i have 2 slots for weapons.
The weapon is instantiated in the right place, its just not following the movement it should.
This is the syncronization code:
void OnPhotonSerializeView (PhotonStream stream, PhotonMessageInfo info) {
if (stream.isWriting) {
stream.SendNext (WeaponAttacher.transform.rotation);
stream.SendNext (WeaponAttacher.transform.position);
stream.SendNext (WeaponSlot.transform.position);
stream.SendNext (WeaponSlot.transform.rotation);
stream.SendNext (transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").position);
stream.SendNext (transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").rotation);
} else {
WeaponAttacherRecievedRotation = (Quaternion) stream.ReceiveNext();
WeaponAttacherRecievedPosition = (Vector3) stream.ReceiveNext();
WeaponSlotRecievedRotation = (Quaternion)stream.ReceiveNext ();
WeaponSlotRecievedPosition = (Vector3)stream.ReceiveNext();
handBonePosition = (Vector3) stream.ReceiveNext();
handBoneRotation = (Quaternion) stream.ReceiveNext();
}
}
and this is started as a coroutine from the start method after a check if !photonview.ismine:
IEnumerator UpdateData () {
while (true) {
WeaponAttacher.transform.rotation = WeaponAttacherRecievedRotation;
WeaponAttacher.transform.position = WeaponAttacherRecievedPosition;
WeaponSlot.transform.rotation =WeaponSlotRecievedRotation;
WeaponSlot.transform.position = WeaponSlotRecievedPosition;
transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").position = handBonePosition;
transform.Find("metarig/hips/spine/chest/shoulder.L/upper_arm.L/forearm.L/hand.L").rotation = handBoneRotation;
yield return null;
}
}