Quantcast
Channel: Photon Unity Networking (PUN) — Photon Engine
Viewing all articles
Browse latest Browse all 8947

Photon team assignment

$
0
0
So I'm trying to create a moba but can't assign the team properly in the champ select. Basically the last player to join sees everyone as it should be. But everyone else doesn't see the last player. When I run a debug on the last player's client he has a team assigned. But when I run the debug on the other clients the last player's team is null. No ideea why... Here is my code:

void OnJoinedRoom(){
Debug.Log(PhotonNetwork.playerList.Length);
Debug.Log(PhotonNetwork.room.MaxPlayers);
if(PhotonNetwork.playerList.Length <= PhotonNetwork.room.MaxPlayers/2){
Debug.Log("Assigned Red");
PhotonNetwork.player.SetCustomProperties(new Hashtable() {{"team","red"}});
}else{
Debug.Log("Assigned Blue");
PhotonNetwork.player.SetCustomProperties(new Hashtable() {{"team","blue"}});
}
StartCoroutine(Await(1f));
joined = true;
}


void Update(){
if(joined && PhotonNetwork.playerList.Length == 2 && !doOnce){
Debug.Log("Start");
doOnce=true;
//this.GetComponent<PhotonView>().RPC ("StartGame", PhotonTargets.All);
StartCoroutine(Await(3f));
StartGame();
}
}


void StartGame(){
inRoomPanelGo.SetActive(false);
champSelectGo.SetActive(true);
foreach(PhotonPlayer pl in PhotonNetwork.playerList){
Debug.Log(pl.NickName + " IS HERE " + "AND HE IS TEAM " + pl.CustomProperties["team"]);
if((string)pl.CustomProperties["team"]=="blue"){
Debug.Log(pl.NickName + " " + pl.CustomProperties["team"]);
GameObject spawnedCsPlayerBl = Instantiate(csPlayerPrefabBlue, Vector3.zero, Quaternion.identity)
as GameObject;
spawnedCsPlayerBl.transform.SetParent(blueContainer, false);
spawnedCsPlayerBl.transform.GetChild(0).GetComponent().text=pl.NickName;
}else if((string)pl.CustomProperties["team"]=="red"){
Debug.Log(pl.NickName + " " + pl.CustomProperties["team"]);
GameObject spawnedCsPlayerRd = Instantiate(csPlayerPrefabRed, Vector3.zero, Quaternion.identity)
as GameObject;
spawnedCsPlayerRd.transform.SetParent(redContainer, false);
spawnedCsPlayerRd.transform.GetChild(0).GetComponent().text=pl.NickName;
}
}
}

Viewing all articles
Browse latest Browse all 8947

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>