how to assign same randomly choosen time to both players in muliplayer photon?
i am working on a game in which i am just sharing score between two players using photon.i want to assign the same countdown timer to both players when both are in the game scene.Can anyone please guide me.THankyou
Answer by ChristianSimon · Mar 13, 2018 at 10:44 AM
Hi,
there are multiple ways to achieve this. One is to store the 'StartTime' in the Custom Room Properties. This can be done by using the following code snippet:
ExitGames.Client.Photon.Hashtable properties = new ExitGames.Client.Photon.Hashtable() { { "StartTime", PhotonNetwork.time } };
PhotonNetwork.room.SetCustomProperties(properties);
Whenever the room properties are updated, the callback void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
is called on all client that are connected to the room. Having this information ('StartTime'), you can calculate a countdown which is the same for all clients.
hey i am trying to do but don't know exactly where should i put this piece of code,i want to send randomly choose time like [Code] float CountDownTimer=Random.range(10f,20f) [/Code] to server and the opponent also get the same time.
Could you please guide me bit more.:(
As said use the Custom Room Properties as described above. Ins$$anonymous$$d of adding PhotonNetwork.time, add your random value. This gets automatically synchronized across all clients in the room. When OnPhotonCustomRoomPropertiesChanged is called on the client, you can access the value with the same $$anonymous$$ey-Name you have chosen before. In my example it was 'StartTime'.
Another option here would be using PhotonNetwork.RaiseEvent. You can see how this would work by reading the certain section of the RPCs and RaiseEvent documentation page.
Your answer
Follow this Question
Related Questions
Unity Photon Next Step? 0 Answers
Unity Photon Next Step? 0 Answers
Unity Photon Handle Match Data 0 Answers
Both players reach same time how to get result draw in photon unity 1 Answer