When using Network.instantiate, how would one define an additional setting?
For instance, if I were to spawn a gun that has 4 bullets inside, I would call:
On the local code I write: (The gun has a script attached called "GunInfo")
However, not all clients know how many bullets the gun has. How do I synchronize this with them?
An extra note: It would be possible using OnSerializeNetworkView(), but this runs every Update() and is completely unnecessary. It only needs to run once initially so all clients know how many bullets the gun has.
I suppose it's possible using an RPC, but how do I identify the object on all clients? How do I get the network-instantiated gun object on all clients code-wise?
I guess the object you instantiate have a NetworkView attached? If so it's quite easy. RPC calls are send to the objects with a NetworkView with the same ViewID.
Thanks to the property you don't have to worry about syncing.
If you don't have a NetworkView on your object you have to implement some kind of object management that keeps a list of all objects and using own IDs to find the corresponding objects.
Do you use an authoritative server setup? Or a "normal mixed" setup where clients can create objects? The only important thing regarding my solution is to keep in mind that only the player that created the object can sync the bullet count.
answered Feb 08 '11 at 03:40 PM