I have just discovered the power of unity, however the network aspect is still making me scratch my head. I am trying to parent a weapon(equipment) to another invisible gameobject on the players hand(EquipmentSlots).
It works well on my client. However, the other players cannot see the weapon attach to my hand. I am still trying to do more research on RPC function calls, but I believe I am doing this somewhat correct.
In the network view of the object I set the state synchronization to off as told by numerous tutorials.
If anyone could please help to explain to me how to “update” the data of the object(i.e. the parent change and position change) over the network, it would be greatly appreciated!
if(equipment[0])
{
slot = 0;
networkView.RPC("equipGun", RPCMode.AllBuffered, slot);
}
[RPC]
public void equipGun(int slot)
{
if(networkView.isMine)
{
equipment[slot].transform.parent = EquipmentSlots[slot];
equipment[slot].transform.position = new Vector3(EquipmentSlots[slot].position.x,
EquipmentSlots[slot].position.y,
EquipmentSlots[slot].position.z);
equipment[slot].transform.rotation = new Quaternion(EquipmentSlots[slot].rotation.x,
EquipmentSlots[slot].rotation.y,
EquipmentSlots[slot].rotation.z,
EquipmentSlots[slot].rotation.w);
equipment[slot].collider.enabled = false;
}
}
What is the purpose of
– asafsitnerif(networkView.isMine)? The RPC will get to the networkView of the same networkViewID that sent the message, meaning it will only be picked up by your clones on the other players's machines. That if statement is going to return true only for each player's local avatar so they never update the data for your clone.