Is syncing a variable only once with Onphotonserializeview possible?
Options
Hi there, I have a quick question.
My game concept has cannons with long reload times like 30 seconds. So, whenever a player got hit, its health gets reduced and updated at all clients. Considering it is a 1v1 instance, the health wont be updated for another 30 seconds.
I use Onphotonserializeview syncing the health value. However, the health variable gets synced all the time continuously, which is not necessary. I have tried to use some bool variables to only update the health once, when it is modified, with no success.
What I wanted to ask is whether there is a way to sync health value (or any value) only at once, when it gets changed instead of sending updated all the time?
My game concept has cannons with long reload times like 30 seconds. So, whenever a player got hit, its health gets reduced and updated at all clients. Considering it is a 1v1 instance, the health wont be updated for another 30 seconds.
I use Onphotonserializeview syncing the health value. However, the health variable gets synced all the time continuously, which is not necessary. I have tried to use some bool variables to only update the health once, when it is modified, with no success.
What I wanted to ask is whether there is a way to sync health value (or any value) only at once, when it gets changed instead of sending updated all the time?
0
Answers
-
I tried something out, see if it works!
private bool canSync;
IEnumerator sync()
{
canSync = false;
yield return new WaitForSeconds(30);
canSync = true;
}
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
{
if (stream.IsWriting)
{
StartCoroutine(sync());
if (canSync)
{
//DoStuff
}
}
else
{
if (canSync)
{
//DoStuff
}
}
}0