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