- Home /
Network Game: Pickups for certain player
Hi. Sorry for plaguing the community with this kind of topic. But searching Google has yielded partial results, and I'm sort of in a bind.
I have asteroids in the scene that have been network-instantiated for everyone. An asteroid should drop a pickup for the player who destroyed it. This pickup can only be seen and collected by that player as well.
Any advice on working with NetworkViews and RPC calls in this regard will be appreciated. Thanks.
You need to send an RPC to destroy the asteroid for all players, but the pickup should only be spawned locally. This can be done several ways, but work on destroying it across the network first, then just spawn the item using a non-RPC method.
I can destroy an asteroid across the network using Network.Destroy(view.viewID)
, and that works because the asteroids were network instantiated.
I have a collectible manager object that allows any class to create a pickup packed with items:
public static void CreateCollectibleBundle(Vector3 pos, params Collectible[] items)
{
CollectibleBundle cb = (CollectibleBundle)Instantiate(
instance.cBundlePrefab,
pos,
Quaternion.AngleAxis(0f, Vector3.up));
cb.items = items;
}
A problem with that is clients do not "see" the pickup that was dropped like the server can, but they can collide into and s$$anonymous$$l it.
Oh...your question makes it seem like that's the behavior you want. Ok, then you should consider making your CreateCollectibleBundle an RPC method as well. See more info here.