- Home /
Photon Unity Networking: Teams?
Hello! I'm making a multiplayer space game. I need teams for my game to be engaging or fun, but I'm not 100% sure how to do it. I have an overall concept on how it will work, but I'm not sure how if this will work or if there is a more efficient way of doing this.
My plan:
When a player connects, a function is called on a 'game controller' script which asks "This player needs a team!", and sends his gameobject's address in the hierarchy to the script.
The game controller checks the red team value and compares it against the blue team value. If one team has a lower amount of players than another team, put the player on the team with the lower count of players (This will sort of balance it.) If they are equal, choose red.
Once the game controller selected a team for the player, the game controller locates the player's gameobject and sets the "ship controller" script's team value to either RED or BLUE. The script will resolve any friendly fire, and it should work.
Please tell me if this is a rock solid plan, if there are any flaws, or if there are places for this to be improved. Thanks for your time!
Answer by CaptainMadbeard · Jan 08, 2015 at 05:35 AM
This plan does seem pretty solid, but you should probably use a Random.Range() command between 1 and 2 inclusive to decide where a player gets put when teams are equal. Otherwise, red team may gain an unfair advantage by having an extra player by default.
Answer by NickK10 · Feb 08, 2015 at 12:19 AM
CaptainMadbeard said it exactly how it needs to be done.
int RandomSelection() {
int team = Random.Range(0, 1);
return team;
}
//Then you can just do a simple.
if(RandomSelection() == 0) {
team = "red";
} else {
team = "blue";
}
Just to make it fair. When equal.
Your answer
![](https://koobas.hobune.stream/wayback/20220613142606im_/https://answers.unity.com/themes/thub/images/avi.jpg)