I am begining to code network games in Unity. I tried to code the Island Demo game to play in network based on Network example that is in the Unity site. But I had problems to synchronizing the positions of the network players. Code (csharp): //NetworkRigidbody.cs NEW! Vector3 pos; Quaternion rot; function OnSerializeNetworkView (stream : BitStream, info : NetworkMessageInfo) { if (stream.isWriting) { // Sending Vector3 posNet = transform.position; Quaternion rotNet = transform.rotation; stream.Serialize(ref posNet); strem.Serialize(ref rotNet); } else { // Receiving Vector3 posNet = Vector3.Zero; Quaternion rotNet = Quaternion.identity; stream.Serialize(ref posNet); strem.Serialize(ref rotNet); pos = posNet; rot = rotNet; } } function Update() { transform.position = pos; transform.rotation = rot; } The "First Person Controller Prefab" had a camera, Graphics and a bunker to quickly visualize the prefab. I put a network view on this prefab to view the NetworkRigidbody.cs that is in it too. But when I tried to move the player all players move too. I didn't understand very well how the synchronizing works in Unity. Can somebody help me? How should I change the code to work correctly? Thx!
Well just an idea, but have you tried addin networkviews to player objects and make the observe the transform componet of that object? Seems like youre over complaicating a bit.
I added networkviews to the player objects and I make them to observe the script above like the Network Example. I just don't understand how do the Update function works in this code. How do the code recognize that the transform component, specified in the function, belongs to a client? How it works? The player prefab calls "First Person Controller Prefab" like Island Demo project. The prefab contains FPSWalker, MouseLook, NetworkRigidbody and CarNetworkInit (without the camera line code) scripts and its children are a camera, a graphics and a simple bunker to visualize the player. I tried a lot but it doesn't work =/
the script is assigned to the corresponding object it wants to alter (that means that transform is the transform of the object the component is assigned to). This linking is done on the prefab thats then beeing instantiated for all remote players.