- Home /
Accessing Static member in multiple instance of Same Script
Hello All, I'm working on a multiplayer game. In this game I've a timer script to synchronize time between clients. I'm using a static variable in this script to start a function at the same time on both the scripts.
void Update ()
{
if (ConnectedIds.Count == 2 && once && PhotonNetwork.isMasterClient)
{
// Timestart = true;
once = false;
this.gameObject.GetComponent<PhotonView>().RPC("StartGameTimeBool",PhotonTargets.AllBuffered);
InvokeRepeating("SyncTime",10,15);
}
// Debug.Log ("Time Status: " + Timestart);
if(Timestart)
{
TimeDelta = PhotonNetwork.time - heapTime;
// Debug.Log("Photon Networking Time: " + lateTime);
startTime += TimeDelta;
GameTime = (int)((float)startTime);
UpdateString(GameTime.ToString());
Debug.Log ("Time Delta: " + TimeDelta + " Start Time: " + startTime);
heapTime = PhotonNetwork.time;
}
CheckTimeforState ();
}
[RPC]
void StartGameTimeBool()
{
Timestart = true;
heapTime = PhotonNetwork.time;
// Debug.Log ("Heap Time: " + heapTime);
}
TimeStart is a static bool So when its true on either of the script, functions depending on this bool starts automatically. This is clear theoretically. Now in practical purpose sometime one of the client get hanged, so I restart that client and connect to other client again. On restarting the client, t*his static bool link on both of the script breaks*, i.e: if its turned true on one client, it doesn't get turned on, other side. I want to know how can I solve this problem. Your suggestion are valuable to me. If you know what can be done please comment.