Check if all players are ready
Options
Hi kinda new just trying to figure out how to check all the player's states, so I can deactivate a canvas once all players have entered an answer. Been struggling for the past 5 hours The code is just a bit of a hack job since I'm rushing to finish, but it does work.
private void SetReadyUp(bool state)
{
_ready = state;
if (_ready)
{
Debug.Log("Ready");
}
else
{
Debug.Log("Not Ready");
}
}
public void Done()
{
waitingForPlayers.SetActive(true);
if (___________?____________)
{
answerScreen.SetActive(false);
}
else
{
SetReadyUp(!_ready);
base.photonView.RPC("RPC_ChangeReadyState", RpcTarget.MasterClient, PhotonNetwork.LocalPlayer, _ready);
}
}
[PunRPC]
private void RPC_ChangeReadyState(Player player, bool ready)
{
int index = _listings.FindIndex(x => x.Player == player);
if (index != -1)
_listings[index].Ready = ready;
}
private void SetReadyUp(bool state)
{
_ready = state;
if (_ready)
{
Debug.Log("Ready");
}
else
{
Debug.Log("Not Ready");
}
}
public void Done()
{
waitingForPlayers.SetActive(true);
if (___________?____________)
{
answerScreen.SetActive(false);
}
else
{
SetReadyUp(!_ready);
base.photonView.RPC("RPC_ChangeReadyState", RpcTarget.MasterClient, PhotonNetwork.LocalPlayer, _ready);
}
}
[PunRPC]
private void RPC_ChangeReadyState(Player player, bool ready)
{
int index = _listings.FindIndex(x => x.Player == player);
if (index != -1)
_listings[index].Ready = ready;
}
0
Comments
-
Have you considered using custom player properties? They are typically used for this kind of data.
Here is a link to a previous post
You'd then usepublic override void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
To check when any properties have been changed.1 -
Have a look at the Asteroids Demo. It has a check for "is ready".0