Countdown timer
Options
Hello , I'm trying to make a system for online racing , but I have a problem with countdown timer .
First I set countdown timer on the master client . Here it's the method ( SetCountDown() )
public void SetCountDown()
{
StartTime = PhotonNetwork.ServerTimestamp;
PhotonNetwork.CurrentRoom.CustomProperties["StartTime"] = StartTime;
PhotonNetwork.CurrentRoom.CustomProperties["IsAnyRace"] = true;
}
And after that , the admin call all the players that participate to race via PunRPC (to flag that race countdown started) and every player who participate to race - check TotalTime if it's lower than 5f(count down timer) . It's working fine on masterClient , but for other players , GetTotalTime() get a value like 20000 (very large)
private float GetTotalTime() // Get total time until now from starting racing
{
StartTimeRace = (int) PhotonNetwork.CurrentRoom.CustomProperties["StartTime"];
int timer = PhotonNetwork.ServerTimestamp - StartTimeRace;
return timer / 1000f;
}
I think that the problem might be : when the admin set "StartTime" - it's not getting updated instantly . I would love to get any help . Thanks !
First I set countdown timer on the master client . Here it's the method ( SetCountDown() )
public void SetCountDown()
{
StartTime = PhotonNetwork.ServerTimestamp;
PhotonNetwork.CurrentRoom.CustomProperties["StartTime"] = StartTime;
PhotonNetwork.CurrentRoom.CustomProperties["IsAnyRace"] = true;
}
And after that , the admin call all the players that participate to race via PunRPC (to flag that race countdown started) and every player who participate to race - check TotalTime if it's lower than 5f(count down timer) . It's working fine on masterClient , but for other players , GetTotalTime() get a value like 20000 (very large)
private float GetTotalTime() // Get total time until now from starting racing
{
StartTimeRace = (int) PhotonNetwork.CurrentRoom.CustomProperties["StartTime"];
int timer = PhotonNetwork.ServerTimestamp - StartTimeRace;
return timer / 1000f;
}
I think that the problem might be : when the admin set "StartTime" - it's not getting updated instantly . I would love to get any help . Thanks !
0
Comments
-
I resolved by setting StartTime via room property and for the other players I'm waiting for OnRoomPropertiesUpdate call ,and after that I can safely get "StartTime" value from customproperties . I don't know if it's from network delay but it's quite logic to be from that , because it's something on the network (every time is a delay of some milliseconds or maybe some seconds)1