Question by
Ali-Present · Feb 20, 2017 at 07:42 PM ·
networkingphoton
Problem in Setting Photon Teams
Hi , i have problem with setting teams in photon. i want to set half of my players in room to be in the Blue PUN team. it's realy simple code but acting Wierd , the code have to apply for amount of " count " but doing more and make all of my players in room turn to blue.
here is my code :
using UnityEngine;
using System.Collections;
public class AutoBalancer : MonoBehaviour {
int count;
void Start ()
{
count = (PhotonNetwork.room.PlayerCount / 2) + 1;
foreach (PhotonPlayer player in PhotonNetwork.playerList)
{
count -= 1;
if (count > 0)
{
player.SetTeam(PunTeams.Team.blue);
}
}
}
}
Comment
Best Answer
Answer by Nischo · Feb 22, 2017 at 12:39 PM
Your code looks overly complicated. Also i think there is a Neutral team, i would set the red team aswell to be safe
count = Mathf.Round(PhotonNetwork.room.PlayerCount / 2.0f);
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);
}
Answer by Ali-Present · Feb 22, 2017 at 10:05 PM
count = Mathf.Round(PhotonNetwork.room.PlayerCount / 2.0f);
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);
}
Thanks dude this works just perfect . /Like :))
Your answer
![](https://koobas.hobune.stream/wayback/20220612111458im_/https://answers.unity.com/themes/thub/images/avi.jpg)