Photon Day Night Cycle Unsynced

Soooo, basically I have a survival game where there is a day night cycle, but since the start of the day is hard-coded by setting the time, when you join a server that has a different time and the default starting time, the time won’t be synced when playing in a server. And I need help on how to sync it across the server. I have tried Googling it, but whenever someone tries to answer, they just give VERY unspecific answers, with no explanation on how to actually accomplish this.

You’re going to want the day/night cycle to be controlled by a float variable. The basic idea of syncing the cycle is that when you are connected to a room, the master client gives you its cycle float value every frame and then you adjust your cycle according to that variable. For example night could be represented as 5 and day could be represented as 10 clamped to 0 (if it goes past 10 then it goes back to 0). So say its night time in the server that you join: When you join the master client will give you a value of 5 and then you change your cycle. So for the actual code:

Your going to need to edit your cycle script and the gameObject on which it is placed. On its gameObject add a PhotonView and then add this to the script after the Update function add:

[RPC]
void getTime(float time){
//Change your cycle according to the received time
}

In the Update() function for your day/night cycle script add:

if(PhotonNetwork.isMasterClient){
GetComponent<PhotonView>().RPC("getTime", PhotonTargets.Others, time);
}

The above RPC is received by ALL players EVERY frame so that if you change the time for yourself then EVERY player’s day/night cycle is adjusted immediately. If you don’t care about updating the cycle every frame then you could be the second part of the script (the rpc call) on a timer so that it only calls every 10 seconds or so. If you do that then you will need to lerp the cycle for each non-Master-Client so that it looks smooth.