- Home /
Photon enable/disable objects on all views?
Hi. I have added multiplayer to my game using Photon Cloud (PUN+).
My problem is, that when my script disables/enables an object, that does not happen on the other client's view.
I know this is how Photon handles multiplayer, but what would be the best way of disabling/enabling gameobjects on both views/clients?
Thannks, Andreas.
Answer by Jellezilla · Apr 23, 2014 at 10:27 AM
I'm not sure from your description, how far you are in the process, so this may be somewhat unprecise.
In order to call methods etc., for a specific client, you need to check ownership. This can be pretty simple with PUN. The client who instantiates an object, will also be the owner of said object. The check is performed by "photonView.isMine()".
if(photonView.isMine()) {
// do something for this specific client
}
If however, you already are able to make changes, specific to the clients, then I'm guessing your issue is to make it apply it on the server, so that all other clients can see it. This is typically done by either streaming the data through [serialization][1] or by using [Remote Procedure Calls (RPCs)][2] OBS: I was unable to find the documentation for Photons own RPC methods, but they are very similar to Unity's RPCs. Major difference is how you call it: instead of Network.RPC("method_Name", targets), you have to use PhotonView.RPC("method_Name", targets);
The Marco Polo tutorial found at [exitgames][3], gives a nice overview of how data streaming can be done, especially under the "Adding Animations" paragraph.
Hope this proves useful to you. Good luck :) [1]: http://doc.exitgames.com/en/realtime/current/reference/serialization-in-photon [2]: https://docs.unity3d.com/Documentation/ScriptReference/NetworkView.RPC.html [3]: http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo
I am using a variable that will turn off/on a sprite in update and I have serialized in serializeview function for the other players like sendnext and receive next, This works very charm in single/local player, but when a player joins, the sprite not getting disabled in the other playerside. Do we need RPC compulsory for this ???