- Home /
Networked Ready check
Trying to create a ready check so that all players will load into the game scene at the same time, I believe the best way to do this is using the Custom player properties associated with PUN 2. The obvious way to me is to do this in a foreach loop but cannot seem to get it working
What I currently have
private ExitGames.Client.Photon.Hashtable _playerCustomProperties = new ExitGames.Client.Photon.Hashtable();
private void HeroSelect()
{
playerReady = true;
selectedHero = "PlayerTest";
PhotonNetwork.SetPlayerCustomProperties(_playerCustomProperties);
_playerCustomProperties["PlayerReady"] = playerReady;
}
public void OnClickHeroButton()
{
HeroSelect();
if (PhotonNetwork.IsMasterClient)
{
foreach (var photonPlayer in PhotonNetwork.PlayerList)
{
PhotonNetwork.PlayerList[photonPlayer].CustomProperties["PlayerReady"] = true;
}
}
}
Unsure if the top line is necessary but the error I am getting is in the foreach loop with the
PhotonNetwork.PlayerList[photonPlayer]
error is:
Cannot implicitly convert type to "Photon.realtime.player" to int
Answer by lgarczyn · Dec 19, 2019 at 04:41 PM
You are trying to use a Player as an index in the player list. Even if this worked for some reason (if the list were a Dictionary that used Player as a key), it wouldn't make any sense to do so, as you already have the photon player variable. Just do:
photonPlayer.CustomProperties["PlayerReady"] = true;
Your answer
Follow this Question
Related Questions
Mirror : How to Sync child objects active status on join? 0 Answers
Unity Photon Ready check 0 Answers
How do I use UNetWeaver.dll during runtime? 0 Answers
How to make sure than one script affect the player of the specific client, and not the other 2 Answers
UnityWebRequest - login page returns a "not found" 0 Answers