Synchronize variable for all players playing the game (include the players in different room)
Options
Hello !
I make a simple 2D game in unity with PUN. In my game i have a feature like 'Jackpot'. When player lose the round, the variable of the Jackpot increase by 1000. I can let other players in the same room to update the jackpot but not other players on other rooms or in lobby.
Is there a way to tell other players not in the same room or currently in lobby to increase the jackpot value by 1000 ? Please help. Thanks !
I make a simple 2D game in unity with PUN. In my game i have a feature like 'Jackpot'. When player lose the round, the variable of the Jackpot increase by 1000. I can let other players in the same room to update the jackpot but not other players on other rooms or in lobby.
Is there a way to tell other players not in the same room or currently in lobby to increase the jackpot value by 1000 ? Please help. Thanks !
0
Comments
-
that's not possible but you could achieve this in a dirty way.
You can give your room a custom property like jackpot and this value can be modified after the room is created.
in the lobby you can list all jackpots and take the jackpot that has the highest value.
http://forum.photonengine.com/discussion/1410/room-properties
according to that post the custom properties are updated
0 -
for players in another room, you cannot use this approach and as far as I know there is none.
you will have to implement your own stuff e.g. like storing the value in a database or if it is really just one value a .txt will do it, too that can be changed via a simply php script
php should be available on any cheap or free webspace https://www.bplaced.net/?lang=en1 -
Thanks for reply once again @kk99 .
Yes, right now i am storing the value in database. I am getting the value by using WWWRequest in Unity.
I am thinking about calling the WWWRequest function every 5 seconds using invokerepeating to get the value. What do you think? is it good to get it this way?0 -
yes, thats bascially the way to go, 5 seconds sounds good
but if you are familiar with databases I can (little) recommend realtime database Google Firebase for Unity https://firebase.google.com/docs/unity/setup
if you use that you won't need to do any calls because Firebase will push any changes immediately to all connectet clients.
I have already played around with it and the basic stuff is working pretty good.
The more complex authentication stuff is still buggie, at least from what I experienced but I guess you wont need that anyway
1