|
Hi, 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? Thanks, Nick
(comments are locked)
|
|
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. Bunny's got the right solution here. My question is, why do clients care how many bullets other clients have?
Feb 08 '11 at 03:46 PM
PrimeDerektive
Thanks Bunny, I'll try it out! Derek, the gun was just an simple example I thought about, so I wouldn't have to explain my own complex situation ;)
Feb 08 '11 at 03:58 PM
Nikke
What is the networkView.isMine for? Isn't the networkView always a component of the current gameobject it is attached to?
Feb 08 '11 at 04:19 PM
Nikke
isMine is just a easier way to check the owner (creator) of that NetworkViewID. It's the same as (networkView.viewID.isMine) or (networkView.viewID.owner == Network.player)
Feb 08 '11 at 04:45 PM
Bunny83
What bunny said. The owner part is not referring to the object that owns it, but rather the network player that owns it (if you're using network.instantiate, the network player that called network.instantiate).
Feb 08 '11 at 04:50 PM
PrimeDerektive
(comments are locked)
|
