PunTeam how to get player tem red or blue count ?
i use this line Debug.Log( PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count)
and recive null reference, i need help =/
and recive null reference, i need help =/
0
Answers
-
Hi @Valakinhas,
PunTeams.PlayersPerTeam is a dictionary containing the Team itself as key and a list of players, which have joined that team, as value. To get the number of for a certain team, you have to access the Count property of the value of a certain Key-Value-Pair. For example for the blue team:PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count
. Please make sure to add the PunTeams script as a component to a game object before trying to access PlayersPerTeam.1 -
Not work, this is a bug =\0
-
Can you share some more details why you are thinking that this is bug? It has been working in my test so far.0
-
my player have
void OnJoinedRoom()Christian_Simon said:Can you share some more details why you are thinking that this is bug? It has been working in my test so far.
{
for (int i = 0; i < PhotonNetwork.room.PlayerCount; i++)
{
var team = PunTeams.Team.blue;
if (i >= count)
{
team = PunTeams.Team.red;
}
PhotonNetwork.playerList[i].SetTeam(team);
Debug.Log(PunTeams.PlayersPerTeam[PunTeams.Team.blue].Count); // null reference
}
0 -
Have you attached the PunTeams script as a component to any GameObject in the same scene where you try to access it from code? It won't work if the component is not attached to an existing GameObject.
A hint to the code snippets: each client who joins the room, will probably assign a new team to each client in the room. If this is wanted behaviour, it's fine. Otherwise you can try getting rid of the for-loop and only assign a team to the client who joined the room (OnJoinedRoom callback).0 -
have GameObject and PhotonviewChristian_Simon said:Have you attached the PunTeams script as a component to any GameObject in the same scene where you try to access it from code? It won't work if the component is not attached to an existing GameObject.
A hint to the code snippets: each client who joins the room, will probably assign a new team to each client in the room. If this is wanted behaviour, it's fine. Otherwise you can try getting rid of the for-loop and only assign a team to the client who joined the room (OnJoinedRoom callback).0