Reputation: 149
I'm using Photon Unity Networking and I am working on a little game of mine.
I got to a point where I have a room with players and mobs. When a new player appears I use RPC call to update information about this player to all other connected users to get synchronized. The problem is.. that this new player does not have any information about the rest of the room (his info is not up to date). I mean for instance current health of other players, or current health of mobs, etc.
The only only solution I came up with is to send an RPC to a master client, pass through all volatile objects around and send several RPC calls back to the new player with this update.
What I am asking is... do I really have to it like this? Or is there any other way, any better or simpler way?
Upvotes: 0
Views: 1373
Reputation: 1
Okay so the phonton networking works via photon network view - and its observed components, means scripts in this observed script you have to pass (if its your character and you are controlling it)
m_PhotonView = GetComponent<PhotonView>(); //Variable
if( m_PhotonView.isMine == true ) //in Void Update()
all variables you need, position, rotation, name, health, relevant data for animations and so on by using SetSynchronizedValues()
Variable = GetComponent<PhotonTransformView>();
Variable .SetSynchronizedValues( Position, Health , Name);
and it will synchronise the Variables, then you have to use them (display the name, set the object to the correct position , show a health bar and resize it) if it's an non controlled character only
if( m_PhotonView.isMine == false)
Hope I could help you
Upvotes: 0