#Teams system

1 messages · Page 1 of 1 (latest)

tranquil ocean
#

I am currently making a game in unity 2023 and i was trying to make teams I wrote this
public override void OnJoinedRoom()
{
Camera.SetActive(false);
base.OnJoinedRoom();
Debug.Log("connected to room.");
teamselector();
spawnPlayer();
}

public void spawnPlayer()
{
if (team == 1)
{
Debug.Log("team A");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPointA.position, Quaternion.identity);
_player.GetComponent<playersetup>().IsLocalPlayer();
_player.GetComponent<health>().islocalplayer = true;
_player.GetComponent<PhotonView>().RPC("setuser", RpcTarget.All, Username);
_player.GetComponent<Renderer>().material.color = Color.red;
}
else if (team == 0)
{
Debug.Log("team B");
GameObject _player = PhotonNetwork.Instantiate(player.name, spawnPointB.position, Quaternion.identity);
_player.GetComponent<playersetup>().IsLocalPlayer();
_player.GetComponent<health>().islocalplayer = true;
_player.GetComponent<PhotonView>().RPC("setuser", RpcTarget.All, Username);
_player.GetComponent<Renderer>().material.color = Color.blue;
}
}

public void teamselector()
{
Debug.Log("selcting team");
if (NextTeam == 0)
{
team = 0;
NextTeam = 1;
}
else if (NextTeam == 1)
{
team = 1;
NextTeam = 0;
}
}
it puts you on a team but it puts everyone on a team and i want to know a way to fix this

tranquil ocean
#

sorry if my code is bad

elder stump
#

I don't use Photon, but you'll want to make sure that only the host/server is running the teamSelector() function

tranquil ocean
elder stump
#

I know it has a shared authority mode. But there should be a room owner

tranquil ocean
#

ok

#

i fixed my problem

#

I checked how many players where online

#

and check if it was odd or even

#

then put them on said team